我想做与使用正则表达式排除字符串中的几乎相同的操作,但我想使用正则表达式来做 iOS。所以我基本上想在字符串中找到匹配项,然后将它们从字符串中删除,所以如果我有这样的字符串,Hello #world @something我想找到#world&@something然后将它们从字符串中删除,这样它就变成了Hello. 我已经有这个表达式可以删除#world,something但不是@,#[\\p{Letter}]+|[^@]+$我@通过这样做解决了这个问题
NSString *stringWithoutAt = [input stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"@%@",atString] withString:@""];
NSString *stringWithoutTag = [input stringByReplacingOccurrencesOfString:tagString withString:@""];
所以对于第一个我结束Hello #world和第二个Hello @something。但是有没有办法使用正则表达式或其他方法同时删除 the#world和 the @something?