-
Notifications
You must be signed in to change notification settings - Fork 4
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
[Feature] Use library regex
to offer extended features
#97
Comments
Hi @slevithan, sorry for late reply. Could you explain in simple terms the concepts you are proposing? What are the corresponding JS regex patterns for |
Here's the syntax for these features in the regex flavors that support then (PCRE, Perl, etc., as well as the
These are powerful features not supported by native JS regexes, except when using the
I'd recommend reading the corresponding sections in the I'd be happy to answer any further questions to help clarify! |
Ok, so to clarify your idea, it's is to implement these more advanced regex features and integrate them as regex construct functions (e.g. Regarding particular features:
Regarding having dependencies on other packages I am against it, as it would significantly increase bundle size. Regex Builder is designed to have minimal (reasonable) bundle size, so it's feasible to use in web apps with minimal perf impact. That's why it's fully tree-shakable, etc. There is a trade-off between having a small bundle size vs having more advanced features. In that dilemma I would rather focus on 80% users using most common 80% features, rather than having most comprehensive regex library out there. That being said, it would be possible to add these more advanced features in following ways:
@slevithan wdyt? |
My subjective opinion though is that it’s possible to overly focus on size in a library like this. Many people significantly concerned about bundle size would likely skip
Yes, based on the linked docs page, In any case, feel to close this if you don't think this is something you'll pursue. |
Thoughts on using the regex library under the hood?
This would allow offering some unique/powerful features, including atomic groups and subroutines.
No worries if you think it's not the right fit. But otherwise, this could show up, for example, as:
subroutine(name)
refSubpattern(name)
.atomic(…)
atomic
could also be a boolean option forchoiceOf(…)
.Additionally, since
regex
supports possessive quantifiers (from PCRE, Perl, Java, Ruby, Python, etc.), you could easily offer them. E.g., all the quantifier functions could have their options changed to replace thegreedy
property withtype
(with values: 'greedy', 'lazy' (or 'nongreedy' if you prefer), and 'possessive'). You could alternatively include a newpossessive
boolean option in addition togreedy
, but I wouldn't recommend that since there is no precedent in existing regex flavors for lazy+possessive quantifiers (for good reason, since this would effectively mean to just always use the lower bound of any quantifier).With the addition of atomic groups and/or possessive quantifiers, you could rightly describe TS Regex Builder as a great way to avoid ReDoS / catastrophic backtracking.
Introducing
regex
would also mean being able to improve any regexes within TS Regex Builder's source for readability, etc., and would be particularly beneficial if you start offering a library of common patterns (#73). In source, you'd get the full benefits of theregex
library including free spacing and comments, context-aware interpolation, etc.The text was updated successfully, but these errors were encountered: