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

Use a positive lookahead for regex to also get overlapping matches. #19

Closed

Conversation

woutk88
Copy link

@woutk88 woutk88 commented Jan 4, 2022

I ran into an issue where not all images are being replaced when there are consecutive image tags. The first image would be replaced, but the second one would not. This happens because the first part of the second image tag (<img) is part of the first regex match.

I've changed the regex to also find overlapping matches using a 'positive lookahead'. Because lookaheads do not store/consume the match, another (with the original regex) preg_match has been added to actually find the matching parts.

This should solve #16 (and I suspect also yireo/Yireo_Webp2#107), however as mentioned in #16 (comment) using a DOM parser might be more reliable.

…), so consecutive image tags are also replaced.
@nehaaccorin
Copy link

@woutk88 Your changes is not working because of module's update, Can you give solution for latest module?

@jissereitsma
Copy link
Contributor

Sorry for this long delay. I decided to use DOMDocument to search the HTML for img tags (by suggestion of others). This outdates your PR but it also should fix the issue. Because of that, I'm closing this PR. Let me know if things are still not working for you though.

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.

3 participants