For a detailed explanation of zero-width assertion regex for regular expressions, see these articles:
Juejin. Cn/post / 699142…
Blog.51cto.com/cnn237111/7…
Reverse assertion is not supported until Chrome 62.
Github.com/tc39/propos…
Github.com/tc39/propos…
ECMAScript2018 just started supporting lookbehind.
(supplement: named capturing group, it is a similar story: stackoverflow.com/questions/2…).
Chrome62 prior to the regular zero width reverse assertion, JS does not support. Error: Named capturing Group named capturing Group is not supported in Chrome before 62: Named capturing group is not supported in Chrome before 62
For an alternative, please refer to:
Stackoverflow.com/questions/7…
You can do the same thing in a few steps in a normal way.
Such as
let regExp = new RegExp('(? <=get\\()[A-Za-z0-9_\\$]+(? ) = \ \ ');
let ret = 'get(key)'.match(regExp);
console.log(ret[0]); After version 62, the result 'key' can be executed. Before version 62, an error is reported.
Copy the code
Can be replaced by:
let regExp = new RegExp('[get\\(][A-Za-z0-9_\\$]+[\\)]{1}');
let ret = 'get(key)'.match(regExp); // result is '(key)'
let _value = ret[0].substring(1, attr[0].length - 1); // Remove the parentheses
console.log(_value);
Copy the code