Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use positive lookahead in RegExp #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

noscripter
Copy link

Since negative lookbehind is relatively new(which got accepted in ECMAScript in 2018) and only v8 and node.js behind v9 without a flag support it, it's more convenient and compatible to use positive lookahead instead.

ref: https://stackoverflow.com/questions/641407/javascript-negative-lookbehind-equivalent

Since negative lookbehind is relatively new(which got accepted in ECMAScript in 2018) and only v8 and node.js behind v9 without a flag support it, it's more convenient and compatible to use positive lookahead instead.

ref: https://stackoverflow.com/questions/641407/javascript-negative-lookbehind-equivalent
@jonschlinkert
Copy link
Owner

it's more convenient and compatible to use positive lookahead instead.

It doesn't do the same thing. Lookahead and lookbehind don't advance the cursor position, as they're "zero-length" assertions. Thus, (?:[^`]) would return a false-negative at the beginning of the string.

However, I'm glad you brought this up, I'd like to make the regex more compatible. I'll keep this open to discuss. Perhaps we should add some test cases to make sure it works in different scenarios.

@jonschlinkert
Copy link
Owner

and thank you for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants