Python 正規表現で区切り文字をORで指定するサンプル

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

構文
文字列変数名 =’文字1…’
re.split('[,:]’, 文字列変数名)
正規表現で区切り文字(カンマ(,)またはコロン(:))をORで指定します
[,:]は、カンマ(,)またはコロン(:)という正規表現です。
使用例

# coding: utf-8

import re

strA = 'SS,AA:BB,CC'
res = re.split('[,:]', strA)

print(res)

実行結果
['SS’, 'AA’, 'BB’, 'CC’]

Python

Posted by arkgame