次の変数があります。
line="s(a)='asd'"
「s()」を含む部分を探しています。
私は使用してみました:
re.match("s(*)",line)
ただし、 ( )を含む文字は検索できないようです。
それを見つけてPythonで印刷する方法はありますか?
次の変数があります。
line="s(a)='asd'"
「s()」を含む部分を探しています。
私は使用してみました:
re.match("s(*)",line)
ただし、 ( )を含む文字は検索できないようです。
それを見つけてPythonで印刷する方法はありますか?
あなたの正規表現はここで問題です。
以下を使用できます。
>>> line="s(a)='asd'"
>>> print re.findall(r's\([^)]*\)', line)
['s(a)']
正規表現の分割:
s # match letter s
\( # match literal (
[^)]* # Using a negated character class, match 0 more of any char that is not )
\) $ match literal (
r
Python では生の文字列に使用されます。