10

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,051
  • 17
  • 72
  • 131
baudot
  • 1,529
  • 17
  • 32

1 Answers1

22

Add the question mark:

B.*?B

See table 2 in the reference of NSRegularExpression

MByD
  • 129,681
  • 25
  • 254
  • 263