「Python」findallメソッドのサンプル

2021年2月23日

findall()
マッチする部分すべてをリストで取得します
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
import re
str = "ST"
res = re.findall(str,'2infoSTASTeeeST')
if res:
print(res[0])
print(res[1])
else:
print(res)
# coding: utf-8 import re str = "ST" res = re.findall(str,'2infoSTASTeeeST') if res: print(res[0]) print(res[1]) else: print(res)
# coding: utf-8
import re

str = "ST"

res = re.findall(str,'2infoSTASTeeeST')
if res:
      print(res[0]) 
      print(res[1]) 
else:
      print(res)

実行結果
>python test.py
ST
ST

Python

Posted by arkgame