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
Need better Possessive Quantifier example #1
Comments
Here are a few examples. I've modified the regex to demonstrate the issue, now using
Note
It's a bit more difficult to demonstrate why |
Actually, I don't think it's possible to construct a case where |
I have a good application for the Since it's not yet available in ECMAScript, here's the PHP code for it: <?php
# Requires PCRE 4.0 or newer!
$invalidHTMLre = '#</?[^\0- !-@[-`{-\x7f][^\0- !-,:-@[-`{-\x7f]*+(?!>)#gm';
$htmlToAlter = '<div></div><input></input';
echo htmlentities( preg_replace( $invalidHTMLre, '', $htmlToAlter ) );
# htmlentities escapes HTML into plain text
?> This will output |
The current "prevents backtracking" is a bit ambiguous, since it could desugar into multiple similar regexs.
Given
/^(?:a|.b)++$/
(purposefully using?:
, so we can ignore capturing groups for the moment):^(?>a|.b)+$/
/^(?>(?:a|.b)+)$/
(this one is correct)/^(?>(?>a|.b)+)$/
This is explained in more detail in the "Using Atomic Grouping Instead of Possessive Quantifiers" section of https://www.regular-expressions.info/possessive.html.
The text was updated successfully, but these errors were encountered: