【发布时间】:2012-05-13 16:17:47
【问题描述】:
我想做与Excluding strings using regex 几乎相同的操作,但我想在 iOS 上使用 Regex。所以我基本上想在字符串中找到匹配项,然后从字符串中删除它们,所以如果我有这样的字符串,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 结束。但是有没有办法使用正则表达式或其他方法同时删除#world 和@something?
【问题讨论】: