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

regexp-tree does not optimize (\.(?!$)|$))$ #259

Open
kurtextrem opened this issue Oct 20, 2023 · 2 comments
Open

regexp-tree does not optimize (\.(?!$)|$))$ #259

kurtextrem opened this issue Oct 20, 2023 · 2 comments

Comments

@kurtextrem
Copy link
Contributor

kurtextrem commented Oct 20, 2023

Coming from this SO post: https://stackoverflow.com/a/36760050
The regex

^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$

got optimized (by hand) to:

^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$

so, partbefore(\.(?!$)|$))$ can be expressed as (partbefore\.?\b)$, avoiding the negative look-ahead, making the regex smaller.

Maybe worth adding as optimization?

@kurtextrem
Copy link
Contributor Author

cross-referencing this reply from eslint-plugin-regexp: ota-meshi/eslint-plugin-regexp#659 (comment)

The regex is actually not faster, for different reasons. I'm not sure what regexp-tree optimizes for (fastest runtime or smallest regex), so ymmv if or what action you'd want to take. In any case, I want to avoid duplicate work while investigation :)

@kurtextrem kurtextrem changed the title regexp-tree does not optimize (\.(?!$)|$)) to \.?\b regexp-tree does not optimize (\.(?!$)|$)) Oct 21, 2023
@kurtextrem kurtextrem changed the title regexp-tree does not optimize (\.(?!$)|$)) regexp-tree does not optimize (\.(?!$)|$))$ Oct 21, 2023
@DmitrySoshnikov
Copy link
Owner

@kurtextrem thanks for the report. Yes, this would be nice to add - feel free to send a PR in case.

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

No branches or pull requests

2 participants