In JavaScript, how do you use use the backtick (`) in a regular expression?
Sample code:
xtype: 'textfield',
regex: /^[a-zA-Z0-9àâçéèêîïôùû-.,:+*'()=&_ \s\u0060]+$/
In JavaScript, how do you use use the backtick (`) in a regular expression?
Sample code:
xtype: 'textfield',
regex: /^[a-zA-Z0-9àâçéèêîïôùû-.,:+*'()=&_ \s\u0060]+$/
Share
Improve this question
edited Jun 22, 2014 at 1:01
Eric Leschinski
154k96 gold badges422 silver badges337 bronze badges
asked Jul 24, 2013 at 9:24
Java LearnerJava Learner
3213 gold badges10 silver badges26 bronze badges
3
- 1 Works for me. <code>/`/.test('foo`bar') === true && /`/.test('foobar') === false</code> – PleaseStand Commented Jul 24, 2013 at 9:26
- 3 Backtick has no special meaning in regular expressions, you don't need to escape it. – Barmar Commented Jul 24, 2013 at 9:27
- 1 Show us what you tried, the results you got, and what you expected. – HBP Commented Jul 24, 2013 at 9:30
3 Answers
Reset to default 20backtick has no special meaning. you can use it as /`/
, it will work fine.
Use unicode character searches and it should do it. Unicode character code for backtick is \u0060
So /\u0060/
should find you backticks. Tested it on RegexPal and it works.
However, as previous respondent correctly said, ` should just work fine without escaping. You must have the problem somewhere else if it doesn't. But using the unicode will ensure that it will definitely match.
I dont actually think that this character needs escaping, look here for the characters that need escaping
You can also try here to test which I find very helpful.