0

The pattern in this code does not replace the parenthesis. I've also tried "/(|)/g".

var re = "/[^a-z]/g",
   txt = navsel.options[i].text.split(" ")[0], // here I get the text from a select and I split it.
   // What I expect is strings like "(en)" , "(el)" etc
   txt = txt.replace(re," ")

Thanks in advance

2
  • 4
    What is your input text and what are you expecting the output to be ? Commented Nov 16, 2011 at 15:08
  • edited, sorry I didn't specify Commented Nov 16, 2011 at 15:39

2 Answers 2

5

Your regex is a string, this will try to replace that exact string. Regex objects don't have quotes around them, just the delimiters. Try it like this:

var re = /[^a-z]/g,
   txt = navsel.options[i].text.split(" ")[0], // here I get the text from a select and I split it.
   txt = txt.replace(re," ");
Sign up to request clarification or add additional context in comments.

Comments

3

Or if you prefer strings (and a more explicit type):

var re = new RegExp("[^a-z]", "g")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.