On Tue, Feb 16, 2010 at 9:55 AM, martin halter <ma...@me.com> wrote:
>    NSString *regex = @"(?:.*[\\s\\W0-9])*cache(?:[\\s\\W0-9].*)*";

Your regex is pathological. It's not hard to confuse the matcher with
really convoluted regular expressions. Consider this: how is your
pattern any different from...

NSString *regex = @"cache";

Since your atoms before and after "cache" can match 0 or more times,
you could greatly simplify the thing by just not matching at all!
Never mind the .* inside the atoms.

If you want to match the word cache that is surrounded by some sort of
defined separators, I'd suggest:

(^|[\s\W0-9])cache([\s\W0-9]|$)

Broken down:

- the start of the string, or some other selected separator
- cache
- some other selected separator, or the end of the string

That should match cache in this instances:

"cache"
"cache some other stuff"
"some other stuff cache"
"some other cache stuff"
"cache/some other stuff"
"some other stuff/cache"
"some other/cache/stuff"
"cache0some other stuff"
"some other stuff0cache"
"some other1cache2stuff"

But not: "some othercachestuff"

Note: I'm not familiar with the particular flavor of regexes ICU uses.
More used to Java and PCRE. But this is the basic idea.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to