Alex Rivera | Logout

Non-greedy NSRegularExpression

Asked 2012-02-19T21:32:44.700
11

I'm need an NSRegularExpression that matches non-greedily. You know, if there's:

ABABABA

...and I ask it to match B.*B I want it to grab the SMALLEST possible match: BAB, not BABAB.

I've been googling this for an hour now, and I keep finding references to the ICU/XCode regex implementation having support for non-greedy matching, but for the life of me, I can't find the syntax to actually do it anywhere.

Edit
Report

1 Answer

25

Add the question mark:

B.*?B

See table 2 in the reference of NSRegularExpression

answered 2012-02-19T21:38:38.053

Your Answer