I want to do pretty much the same as in Excluding strings using regex but I want to do it iOS using Regex. So I basically I want to find matches in a string and then remove them from the string so if I have a string like this, Hello #world @something I want to find #world & @something and then remove them from the string so it just becomes Hello. I already have this expression that removes #world and something but not the @, #[\\p{Letter}]+|[^@]+$ I solved the @ problem by doing this
NSString *stringWithoutAt = [input stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"@%@",atString] withString:@""];
NSString *stringWithoutTag = [input stringByReplacingOccurrencesOfString:tagString withString:@""];
So for the first one I end up with Hello #world and the second one Hello @something. But is there a way of using Regex or something else to remove both the #world and the @something at the same time?
You can use regex in iPhone in two ways:-
1>Using RegExKitLIte as framework see the tutorial
2>Using NSRegularExpression & NSTextCheckingResult
Here any expression after@ and expression after # is being concatenated
and in the statement you can replace it by space to get your expression
if u simply want modified string do this :-