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.

Emil
  • 7,220
  • 17
  • 76
  • 135
baudot
  • 1,618
  • 20
  • 33

1 Answers1

25

Add the question mark:

B.*?B

See table 2 in the reference of NSRegularExpression

MByD
  • 135,866
  • 28
  • 264
  • 277