regexp-tree
regexp-tree copied to clipboard
regexp-tree does not optimize `(\.(?!$)|$))$`
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?
cross-referencing this reply from eslint-plugin-regexp
: https://github.com/ota-meshi/eslint-plugin-regexp/issues/659#issuecomment-1773046245
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 thanks for the report. Yes, this would be nice to add - feel free to send a PR in case.