0
import re
derp = "This Act may be cited as the `Clean Air Act Amendments of the 101st Congress'."
re.search("(can)|(may) be (cited)|(referred to) as the? `(.+)'",derp).group(5)

这似乎不起作用,我认为它与分组有关。有人可以帮我正确分组条款吗?

4

2 回答 2

3

要在正则表达式中使用字符串选择,请使用以下形式:

(?:can|may)

笔记 :

?:

代表非捕获组,因此无需修改组索引

于 2013-03-11T22:03:44.713 回答
2
  "(can|may) be (cited|referred to) as the? `(.+)'"

并且不要忘记修改您的组索引...

于 2013-03-11T22:06:03.390 回答