javascript - How to write this regular rule to match a string that does not start with a certain character?
PHP中文网
PHP中文网 2017-06-12 09:21:00
0
6
782

Language: JavaScript

is required to match hello, but cannot match abchello. How should I write this regular rule? Have no idea ...

PHP中文网
PHP中文网

认证0级讲师

reply all(6)
小葫芦
console.log(/\bhello\b/.test('abchello')); // false
console.log(/\bhello\b/.test('hello')); // true
漂亮男人

/^hello$/, you may want qui to match the word hello, but not other words containing hello. In this case, you only need one hello, or write it with abc and return false. You can also write two

Ty80

js does not have lookahead, it can only be determined through two matches.

我想大声告诉你

/^hello$/ig.test('abchello'); //false
/hello$/ig.test('abchello'); //true

Cause:

^这个特殊字符表示以什么开始,如果想要随意匹配就将其去掉。
 同样地,$这个特殊字符是结束标志。
世界只因有你

Personally, I think it’s better to use /bhellob/, but this regular rule cannot be matched very accurately. It can only satisfy most situations, not special situations. This is because js’s support for regular expressions is not perfect enough, so you can make do with it for now

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template