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)
这似乎不起作用,我认为它与分组有关。有人可以帮我正确地分组这些条款吗?
答案 0 :(得分:3)
要在正则表达式中使用字符串选项,请使用以下表单:
(?:can|may)
注意:
?:
代表非捕获组,因此无需修改组索引
答案 1 :(得分:2)
"(can|may) be (cited|referred to) as the? `(.+)'"
并且不要忘记修改您的群组索引...