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 に答える