If I have the string “Hello World”, is it possible to use NSRegularExpression with the pattern @”World” to get the position of the match, i.e. in the “Hello World” example the position/index of the match should be “6”?
in php I’d use preg_match with the “PREG_OFFSET_CAPTURE” flag to achieve this, does objective-c support this?
You can do it the Cocoa way:
Or the POSIX way (this may be convenient for you, since you want only one match, and this function/method returns the match range directly):