Python splitメソッドで複数の区切り文字を指定するサンプル

環境
Python 3.9.13
Windows 10 Home 64bit
PyCharm 2022.2.1 (Community Edition)

構文
re.split(':;’, 対象文字列)
コロン(:)とセミコロン(;)の2文字が区切り文字を指定して文字列を分割します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
import re
strA = '123s:456t:;789ki:;999in;mn'
res = re.split(':;', strA)
print(res)
# coding: utf-8 import re strA = '123s:456t:;789ki:;999in;mn' res = re.split(':;', strA) print(res)
# coding: utf-8
import re

strA = '123s:456t:;789ki:;999in;mn'
res = re.split(':;', strA)

print(res)

実行結果
['123s:456t’, '789ki’, '999in;mn’]

Python

Posted by arkgame