#import <objc/objc.h>
#import <objc/Object.h>
#import <Foundation/Foundation.h>
int main( )
{
NSString * pattern = @"(.*)[<]Foobar[>]" ;
NSString * s = @"abcde\n fghij<FooBar>" ;
NSError* regexError = nil;
NSRegularExpression* regex = [ NSRegularExpression regularExpressionWithPattern: pattern
options: NSRegularExpressionDotMatchesLineSeparators
error:& regexError] ;
if ( regexError)
{
NSLog( @"Regex creation failed with error: %@" , [ regexError description] ) ;
return 0 ;
}
NSArray* matches = [ regex matchesInString: s
options: NSMatchingWithoutAnchoringBounds
range: NSMakeRange( 0 , s.length )
] ;
for ( NSTextCheckingResult * match in matches) {
NSRange matchRange = [ match range] ;
NSString * m = [ s substringWithRange: matchRange] ;
NSLog( @"Matched string: %@" , m) ;
}
}
I2ltcG9ydCA8b2JqYy9vYmpjLmg+CiNpbXBvcnQgPG9iamMvT2JqZWN0Lmg+CiNpbXBvcnQgPEZvdW5kYXRpb24vRm91bmRhdGlvbi5oPgoKCmludCBtYWluKCkKewogICAgTlNTdHJpbmcgKnBhdHRlcm4gPSBAIiguKilbPF1Gb29iYXJbPl0iOwogICAgTlNTdHJpbmcgKnMgPSBAImFiY2RlXG4JCWZnaGlqPEZvb0Jhcj4iOwogICAgTlNFcnJvciogcmVnZXhFcnJvciA9IG5pbDsKICAgIE5TUmVndWxhckV4cHJlc3Npb24qIHJlZ2V4ID0gW05TUmVndWxhckV4cHJlc3Npb24gcmVndWxhckV4cHJlc3Npb25XaXRoUGF0dGVybjpwYXR0ZXJuCiAgICAgICBvcHRpb25zOk5TUmVndWxhckV4cHJlc3Npb25Eb3RNYXRjaGVzTGluZVNlcGFyYXRvcnMKICAgICAgIGVycm9yOiZyZWdleEVycm9yXTsKIAogICAgaWYgKHJlZ2V4RXJyb3IpCiAgICB7CiAgICAgICBOU0xvZyhAIlJlZ2V4IGNyZWF0aW9uIGZhaWxlZCB3aXRoIGVycm9yOiAlQCIsIFtyZWdleEVycm9yIGRlc2NyaXB0aW9uXSk7CiAgICAgICByZXR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