How to split a string with multiple separators in Python

1 Answer

0 votes
import re

input_str = "abc,defg;hijk|lmnop-qrst_uvwxyz"

# Match multiple separators: comma, semicolon, pipe, dash, underscore
result = re.split(r"[,\;\|\-_]", input_str)

for word in result:
    print(word)



'''
run:

abc
defg
hijk
lmnop
qrst
uvwxyz

'''

 



answered Jul 21, 2025 by avibootz
edited Jul 21, 2025 by avibootz
...