Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript: How to use (backtick) ` in regular expression?

In JavaScript, how do you use use the backtick (`) in a regular expression?

Sample code:

xtype: 'textfield',
regex: /^[a-zA-Z0-9àâçéèêîïôùû-.,:+*'()=&_ \s\u0060]+$/
like image 917
Java Learner Avatar asked Dec 05 '22 10:12

Java Learner


2 Answers

backtick has no special meaning. you can use it as /`/, it will work fine.

like image 151
schnill Avatar answered Dec 29 '22 03:12

schnill


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.

like image 37
mavili Avatar answered Dec 29 '22 02:12

mavili