Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
文字列があります:
application-label:'I'go Reader'
一致させるには、どの正規表現を (Python で) 記述する必要がありますか。
I'go Reader
注:試しました:
re.search(r"(?<=label\=\')[\d\w\s\' ]+?(?=\')", text)
ただし、最初の '. 2 番目の ' の前の部分文字列まで一致させる方法は?
量指定子を貪欲にして、最長の一致を見つけようとするだけです。
re.search(r"(?<=label\=\')[\d\w\s\' ]+(?=\')", text) # ^^
これがうまくいくかどうかは、あなたの入力次第です。
しかし、これが完全な文字列または各入力が常に patternlabel:'content'に従う場合、最初のコロンで分割して引用符を削除します。
label:'content'
content = text.split(':', 1)[1].strip("'")