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.
私は次の文字列を持っています
'TOKEN a$dmin\r\n'
そして、そこから価値を引き出したいと思い'a$dmin'ます。使っています
'a$dmin'
re.findall("(?i)TOKEN (.*)",string)
しかし、私が得ているのは'a$dmin\r\n'
'a$dmin\r\n'
これを正しく行うにはどうすればよいですか?
どちらかと一致しstr.stripます:
str.strip
re.findall(r"(?i)TOKEN (\S*)", s.strip())
または、スペース以外にのみ一致するように式を変更します。
re.findall(r"(?i)TOKEN (\S*)", s)
次のように、文字通りのスラッシュがある場合:
s = r'TOKEN a$dmin\r\n'
この式を使用して、最初のスラッシュの前のすべてに一致させます。
re.findall(r"(?i)TOKEN (.*?)\\", s)