Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8189515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:18:10+00:00 2026-06-07T03:18:10+00:00

I know that SO is not a code generator, but I break my head

  • 0

I know that SO is not a code generator, but I break my head and I’ll got mad with this RegExp.

I’ve <input /> type text, in a HTML <form />. The input is automatically filled when the user double-click on elements in a specific list.
This event will generate string like "[text:number]" or "[text:number:text]", and place it at the cursor position in my <input /> field.
The first goal of this process is to construct a mathematic formula structure. I mean, the generated strings between brackets will insert elements, then I want to allow the user to put only numbers and operators.

I’ve tried to bind the keydown event, and test the char with String.fromCharCode(e.which); but for the keys “+” or “-” (and other operators) this function returns alphabeticals chars. Without success.
Then, I’ve finally decided to use the keyup event, then use a RegExp to replace the <input /> value.

        $("#inputID").keyup(function(){
            var formule = $(this).val();
            var valid_formule = formule.replace(CRAZY_REGEXP,'');
            $(this).val(valid_formule);
        });

So, my question is as follows :
How construct a javascript RegExp, to remove all chars which are not between brackets, and which are differents of ()+-*/,. and numbers.
An example :
"a[dse:1]a+a[dse:5]a+a[cat:5:sum]a+(a10a/5,5)!"
will become
"[dse:1]+[dse:5]-[cat:5:sum]+(10/5,5)"

I’m open to another way to achieve my goal if you have some ideas.
Thanks !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:18:11+00:00Added an answer on June 7, 2026 at 3:18 am

    You may try something like this:

    var re = /[^\]\d\(\)+\-*\/,.]+(?=[^\[\]\(\)]*(?:\[|\(|$))/g;
    $("#inputID").keyup(function(){
        this.value = this.value.replace(re, "");
    });
    

    Keep in mind, though, that you have to be sure that the parenthetical structure is coherent with your syntax.

    Advice: use RegExr to test your regular expressions, but remember that it’s more powerful than Javascript regex support.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that c++ code should be compiled and linked by g++, not gcc.
I know that the following works but it is not that readable, is there
I know that NSDate does not represent a timezone, but perhaps someone can advise
I know that it's not possible to style any given PHP but I do
this is my first question here :) I know that I should not check
First of all, I know that UDP is not a reliable protocol but I
I know that designing state machine generators for regular expressions is not trivial, but
Since we know that constructor is not inherited in the child class as i
Now while I know that you can not perform inheritance like you would in
Ok, I know that question is not very informative.. Someome feel free to change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.