RegEx pattern with not followed by

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>

Answers


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?


Need Your Help

mySQL Update tuple based on foreign key

php mysql sql-update

Imagine having 2 tables - Vehicles &amp; Manufacturers.

Android + google maps

java android google-maps google-maps-api-3

I want to know if it is possibile with google maps API create a path with more point?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.