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

DON'T BE GREEDY regular expression fix .. #10

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

Conversation

SGudbrandsson
Copy link
Contributor

The regular expression (that I wrote) on line 230 was too greedy.
If the U modifier is used then this is ungreedy by default.
The problem is when you have the question mark behind a quantifier then it will inverse that quantifier's greediness.
So it will search for an iframe open tag, then search for the last iframe close tag (rather than the next iframe close tag).
* ORIGINAL REGEXP **
|<iframe\s+.
?</iframe>|siU

By removing the question mark, the whole expression is not greedy by default, resulting in functionality just like you'd want.
* FIXED REGEXP **
|<iframe\s+.
</iframe>|siU

The regular expression (that I wrote) on line 230 was too greedy.
If the U modifier is used then this is ungreedy by default.
The problem is when you have the question mark behind a quantifier then it will inverse that quantifier's greediness.
So it will search for an iframe open tag, then search for the last iframe close tag (rather than the next iframe close tag).
** ORIGINAL REGEXP **
|<iframe\s+.*?</iframe>|siU

By removing the question mark, the whole expression is not greedy by default, resulting in functionality just like you'd want.
** FIXED REGEXP **
|<iframe\s+.*</iframe>|siU
@SGudbrandsson
Copy link
Contributor Author

oh my .. it removed the code I wrote .. oh well..

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.

1 participant