私は文字列を持っています
1563:37say: 0 kl4|us: !!alias kl4
そして、いくつかの情報を抽出する必要があります。私はこのPythonコードを試しています:
import re
x = "1563:37say: 0 kl4us: !!alias kl4"
res = re.search( r"(?P<say>say(team)?): (?P<id>\d+) (?P<name>\w+): (?P<text>.*)",x)
slot= res.group("id")
text = res.group("text")
say = res.group("say")
name = res.group("name")
このコードは正常に動作します。文字がある場合、|
または*
文字列にある場合、この正規表現が機能しないのはなぜですか?
例えば:
import re
x = "1563:37say: 0 kl4|us: !!alias kl4"
res = re.search( r"(?P<say>say(team)?): (?P<id>\d+) (?P<name>\w+): (?P<text>.*)",x)
slot= res.group("id")
text = res.group("text")
say = res.group("say")
name = res.group("name")
誰でも私を助けることができますか?
どうもありがとう