私はthis is title [[this is translated title]]
という文字列を持っており、これらの2つのサブフィールドを抽出する必要があります。 this is title
、this is translated title
正規表現を使用してPythonで部分文字列を抽出する方法
私は正規表現を使用しようとしましたが、それを完了できませんでした。
def translate(value):
# Values are paseed in the form of
# "This is text [[This is translated text]]"
import re
regex = r"(.+)(\[\[.*\]\])"
match = re.match(regex, value)
# Return text
first = match.group(1)
# Return translated text
second = match.group(2).lstrip("[[").rstrip("]]")
return first, second
しかし、これは失敗します。文字列は「シンプルプレーンテキスト」
あなたが働いていると思われるものを使用してください。どうしたの? – wim