Reputation: 1618
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.
Upvotes: 11
Views: 3794
Reputation: 137282
Add the question mark:
B.*?B
See table 2 in the reference of NSRegularExpression
Upvotes: 25