Click here to Skip to main content
15,616,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using 'highlight textarea' jquery plugin. I need to pass a regex in jquery. But jquery not recognising backslash character even if I use another backslash to escape it.All other special characters works fine except backslash.

          words: ['\(.+?)}'],
          debug: true

if I use below regex to get a string between {},it works fine.
words: ['{(.+?)}']
But to get a string between \},its not recognising this \ character, even the regex is
words: ['\\(.+?)}]

So how to use backslash to be recognised in this regex.
Any help will be greatly appreciated

1 solution

The backslash has meaning in strings and in regular expressions, so you have to escape it twice.

This means that each backslash you want to match must be replaced by four backslashes:
words: ['\\\\(.+?)}']
Share this answer
Vidhya Raju 22-Sep-14 7:49am    
Thanks,It works fine now

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900