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]+$/
backtick 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.
/\`/.test('foo`bar') === true && /\`/.test('foobar') === false
– PleaseStand Jul 24 '13 at 09:26