最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

regex - JavaScript: How to use (backtick) ` in regular expression? - Stack Overflow

programmeradmin1浏览0评论

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
Add a comment  | 

3 Answers 3

Reset to default 20

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.

发布评论

评论列表(0)

  1. 暂无评论