我有一个字符串:"My goal today is to work out 30 minutes [Last update: May 20, 2013 by Joe Smith] and eat healthy"
有人可以NSRegularExpression
在Objective-C中制作一个提取子字符串的方法:
[Last update: May 20, 2013 by Joe Smith]
我想基本上删除方括号之间的字符串部分,[]
以便我的最终字符串变为:“我今天的目标是锻炼 30 分钟并吃得健康”
是正确的正则表达式:
NSRegularExpression *regex =
[NSRegularExpression regularExpressionWithPattern:@"[Last Update:*]"
options:NSRegularExpressionCaseInsensitive error:&error];
我在网上看到了一些以 开头的正则表达式,"\b"
以及其他转义方括号的正则表达式: "\[Last update:*\]"
--但是有了这个,我得到了编译器警告(但不是错误)