Regex - negative lookahead problem

Hi,
I prepeared this regex formula to find all url which contains: domain.com/wp-contet/uploads/
and every file *.jpg except including 360x240, 300x200 or 720x480:

https://domain.com/wp-content/uploads/(?!.(360x240|300x200|720x480)).?.jpg

My goal is to find *.jpg files which are in full size like: domain.com/wp-content/uploads/name-file.jpg (so without resize like: domain.com/wp-content/uploads/name-file-360x240.jpg)

I tested it in regex101.com and works perfectly but in make it does not work.

I tested many times in make and I think there is problem with
(?!.*(360x240|300x200|720x480))

Does make support negative lookahead? Should I change something in this regex above?

Thank you in advance for help

Best regards,
Konrad

It sounds like you’re trying to create a regex pattern to match full-size JPEG files while excluding those with specific resolutions in their filenames. The issue you’re encountering with make likely stems from its limited support for certain regex features, including negative lookaheads.

To address this, you can modify your regex to avoid using negative lookahead altogether. Here’s an alternative approach:

https://domain\.com/wp-content/uploads/[^/]*[^-360x240|-300x200|-720x480]\.jpg

Explanation:

  1. https://domain\.com/wp-content/uploads/: Matches the exact URL prefix.
  2. [^/]*: Matches any characters (except slashes) that could be in the filename.
  3. [^-360x240|-300x200|-720x480]: Ensures that the filename does not include the unwanted resolutions. However, this part needs careful handling to avoid false positives, so you may need to fine-tune it based on actual filenames.
  4. \.jpg: Ensures the filename ends with .jpg.

This regex is less reliant on advanced features and should work in environments with limited regex capabilities, like make.

Testing:

Make sure to test it in your environment to ensure it correctly identifies full-size JPEGs while excluding the specified resolutions. If you continue having issues, you might also consider processing the URLs programmatically (e.g., with a script) to filter them after a broader match.

Welcome to the Make community!

Could you go to regex101.com, paste in your Pattern at the top and paste a complete/full example text you are trying to match from below it?

Then, save the regex example and share the link with us here.

This will allow others to assist you here with your pattern. Thanks!

Welcome to the Make community!

You can use a Text Parser “Match Pattern” module with this Pattern (regular expression):

https:\/\/domain\.com\/wp-content\/uploads\/.+-(?!(?:360x240|300x200|720x480))\d+x\d+\.jpg

Proof https://regex101.com/r/MiMwTB/1

Important Info

  • :warning: Global match must be set to YES!

Screenshot


For more information, see Text Parser in the Make Help Center:

Match Pattern
The Match pattern module enables you to find and extract string elements matching a search pattern from a given text. The search pattern is a regular expression (aka regex or regexp), which is a sequence of characters in which each character is either a metacharacter, having a special meaning, or a regular character that has a literal meaning.

Hope this helps! Let me know if there are any further questions or issues.

— @samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

1 Like

Thank you for your help. It works:)