1

I am trying to replace all the /n, <br> and space in the string and replace them with ''.

My approach is using replace. However, I am getting the following errors.

Uncaught SyntaxError: Unexpected string

I know

console.log(text.value[langID]) would output bunch of texts.

but I got the error when I changed my codes to this.

console.log(text.value[langID].replace('/\n|<br>|\s/g', ''));

I am not sure what went wrong here and if my rex pattern can filter my requirements.

Can anyone gives me a hint?

Thanks so much!

4
  • BEWARE: stackoverflow.com/questions/590747/… Commented Jul 23, 2013 at 20:17
  • @Diodeus He's not parsing HTML, just escaping out certain sequences. Commented Jul 23, 2013 at 20:22
  • As Claudio pointed out, the string is unexpected because you need a comma between the strings. JS doesn't expect you to just mash the strings together. Commented Jul 23, 2013 at 20:24
  • Using a tool like JSHint make spotting these types of syntax errors easier. Commented Jul 23, 2013 at 21:53

1 Answer 1

6

You missed the comma separator for replace parameters. Also, as @Ingo Bürk pointed out, quotes for regex expression are not valid so you have to remove them too

console.log(text.value[langID].replace(/\n|<br>|\s/g,''));
Sign up to request clarification or add additional context in comments.

2 Comments

He should also drop the quotes aorund the regular expression
Thanks, turns out it's just a simple mistake! +1

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.