ICU and Java's regular expression support (and probably other platforms) separate compilation of a regular expression from matching it to a specific string. This improves performance when a common regex pattern is matched with multiple strings, since it only needs to be compiled once.
Is there any way to do this with NSRegularExpression? Its design appears to combine these two steps, if I'm reading the documentation correctly.
They are two steps. First, you create a regular expression:
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<h1>(.*?)</h1>"
options:NSRegularExpressionCaseInsensitive
error:&error];
And then, second, you use it (obviously use whatever method you want):
[regex enumerateMatchesInString:htmlString
options:0
range:NSMakeRange(0, [htmlString length])
usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
// do whatever you want
}];
Am I misunderstanding the question?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With