0

I want to match only first file path, which not contains word Thumbnails. I use "not-followed by pattern" but it doesn`t work. Could some one take a look and tell me where is my mistake? Here is my regex:

<string>((.*(?!Thumbnails))\.jpg)</string>

Strings

<string>/Volumes/Macintosh HD/Users/username/Pictures/iPhoto Library/Masters/2012/05/14/20120514-105314/IMG_6204.JPG</string>
<string>/Volumes/Macintosh HD/Users/username/Pictures/iPhoto Library/Thumbnails/2012/05/14/20120514-105314/IMG_6204.jpg</string>
0

2 Answers 2

1

Your regexp will match file paths which do not contain "Thumbnails" right before the file extension. You want to prevent it from matching those which contain "Thumbnails" anywhere in the text.

You could try something like:

<string>((?!.*Thumbnails).*?\.jpg)</string>

Or:

<string>((?![^<]*Thumbnails)[^<]*\.jpg)</string>

(That will prevent the regexp engine from going past the closing "<" when searching for "Thumbnails". It will also disallow file paths which contain "<".)

I presume you are matching this against individual lines of text, not against a string which contains multiple lines, right?

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, its works perfect. Yes, Im matching strings which contains 1 line.
0
<string>^((?!Thumbnails).)*$</string>

2 Comments

Yes. Probably because I originally wrote "<strong>" instead of "<string>"? :)
The ^ and $ are also not needed. Or if you do want them, they should go at the very beginning and end of the regexp. (<string> can't appear before the beginning of the line.) Also, you need to explicitly match the .jpg suffix which the OP expects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.