1

In this list:

  • image_1.png
  • image_1_small.png
  • image_2.png
  • image_2_small.png
  • image_three.png
  • image_three_small.png
  • antoher_image.png

I would like to match only those images that BEGIN with the word image BUT do not contain the word small.

The regex should then return:

  • image_1.png
  • image_2.png
  • image_three.png

So far I have:

/^image(?!.*small)/m
DMK
  • 2,448
  • 1
  • 24
  • 35
hjrshng
  • 1,675
  • 3
  • 17
  • 30
  • 4
    Which language? And what's the issue? – Rohit Jain Aug 14 '13 at 14:11
  • 5
    Your Regex works. I changed it a bit so you grab the entire filename: [RegexPal](http://regexpal.com/?flags=gm&regex=^%28image%28%3F!.*small%29.*%29&input=image_1.png%0Aimage_1_small.png%0Aimage_2.png%0Aimage_2_small.png%0Aantoher_image.png) – f605dcf7dc5542e93ae9cd76f Aug 14 '13 at 14:15
  • @HamZa I noticed that you keep using `(?!.*small)`, why the `.*` before small ?. Isn't `(?!small)` enough ? – Ibrahim Najjar Aug 14 '13 at 14:18
  • @Sniffer `(?!small)` will only prevent "imagesmall" from matching. It would still match "image_1_small". – Michelle Aug 14 '13 at 14:24
  • @Robit: i'm using cakephp folder api (http://book.cakephp.org/2.0/fr/core-utility-libraries/file-folder.html) to list files. It returned empty value. – hjrshng Aug 14 '13 at 14:51
  • If that's the list, just use `^image_\d+\.png$`, why do you have to intentionally exclude "Small", and what is the Math in this? I think you could have a much more efficient solution if you gave more details. – Suamere Aug 14 '13 at 16:18
  • @Suamere: i meant 'match' (edited). image_*small*.png are auto generated, so i don't want them to be shown in the user file manager. Your regex won't work because it should return ALL the images that begin with **image**, so it should match **image_three.png** too. – hjrshng Aug 16 '13 at 13:18
  • That makes sense then, throw that up in the question as one of the examples to match. – Suamere Aug 16 '13 at 14:57

1 Answers1

1

I tested this with your single lines from the list

 ^image(?!.*_small.*).*\.png$

see also this discussion on how to exclude keywords in regex

Community
  • 1
  • 1
576i
  • 7,579
  • 12
  • 55
  • 92