
1 rming 2015-04-21 11:25:44 +08:00 |
2 weyou 2015-04-21 11:26:40 +08:00 用正则的group啊, \((.*)\) |
3 weyou 2015-04-21 11:30:53 +08:00 >>> import re >>> a = "this is a (test), isn't it" >>> re.search(r'\((.*)\)', a).group(1) 'test' |
4 RangerWolf OP @weyou 感谢~ 如果是仅 .group() 不是 group(1)的话 还是会带圆括号 |
5 zhyu 2015-04-21 13:33:22 +08:00 @RangerWolf re.MatchObject.group([group1, ...]) Returns one or more subgroups of the match. If there is a single argument, the result is a single string; if there are multiple arguments, the result is a tuple with one item per argument. Without arguments, group1 defaults to zero (the whole match is returned). .group()和.group(0)一样,返回的是全部的匹配内容 |
6 wmttom 2015-04-21 14:15:06 +08:00 >>> import re >>> re.search(r"(?<=\()\S+?(?=\))", "aa(bbb)ccc").group() |
7 200cc 2015-04-21 15:31:04 +08:00 var s = 'aa(bbb)ccc'; var r = /\((.*)\)/g; var result = r.exec(s)[1]; // bbb |
8 RangerWolf OP @wmttom 赞!非常感谢! |
9 RangerWolf OP @zhyu 是的~ 只不过之前那位兄弟的正则 还是没把圆括号去掉 |