JavaScript Regex: Alternative to Look Behind Assertion
In JavaScript, the look behind assertion (?) is not supported. This assertion is useful for matching a pattern that is preceded by a specific condition. However, there are alternative ways to achieve the same result in JavaScript.
One alternative is to use the ^ and (?!
^(?:(?!filename\.js$).)*\.js$
This regex explicitly checks each character of the string to ensure that it does not satisfy the look behind condition.
Another simpler alternative introduced in ECMAScript 2018 is to use the following regex:
^(?!.*filename\.js$).*\.js$
This regex uses the . expression to match any string, and the (?!
The above is the detailed content of How to Achieve Look Behind Assertion in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!