Resolved: Regex to Match Two Strings Including Anything in Between Without Line-Breaks

In this post, we will see how to resolve Regex to Match Two Strings Including Anything in Between Without Line-Breaks

Question:

I want to replace all the .png extensions in my HTML to .webp so I am doing the regex expressing to match the png links:
This works ok if my HTML file has line breaks like this:
and it matches all the strings correctly.
but after it’s minified, it’s no longer working, and it matches the start string until the last occurrence of the second string with everything in between, so the following:
will have a match for:
How can I do this with regex after my file is minified?

Best Answer:

Try with /S non-whitespace character matcher instead of . matches to any:
\.\/assets\/images\/\S*\.png
regex101 Demo

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com