Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSString replace regex

I have a string like this:

NSString* msg = @"Hello this is a new message to @[123:Dr Zoidberg] and his nippers";

And I want to use -stringByReplacingMatchesInString:options:range:withTemplate: to convert this pattern to:

NSString* msg = @"Hello this is a new message to Dr Zoidberg and his nippers"; 

This is what I have so far:

NSString* msg = @"Hello this is a new message to @[123:Dr Zoidberg] and his nippers";
NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern: @"????"
                                                                       options: NSRegularExpressionCaseInsensitive
                                                                         error: nil];

NSString* plainText = [regex stringByReplacingMatchesInString: msg
                                                      options: 0
                                                        range: NSMakeRange(0, [msg length])
                                                 withTemplate: @"$2"];

Can anyone help me with the @"????" pattern?

like image 996
Paul de Lange Avatar asked Aug 28 '26 09:08

Paul de Lange


1 Answers

This was the pattern I was after: @(.*?):(.*?)]. Thanks go to this question.

like image 80
Paul de Lange Avatar answered Aug 30 '26 23:08

Paul de Lange