简体   繁体   中英

How to use split() in python with multiple delimeters including whitespace

I need to split below string : at comma, whitespace and pipe,

str1 = "HSQCV,feedback.fetch(stat[c[i]]) 3453 54f|note"

i need to get my output list str1 after splitting as:

['HSQCV', 'feedback.fetch(stat[c[i]])', '3453', '54f', 'note']

也许你可以尝试使用正则表达式

re.split('\s|,|\|', str1)

Use below code , it should work

str1 = "HSQCV,feedback.fetch(stat[c[i]]) 3453 54f|note"
str1=str1.replace(",", " ")
str1=str1.replace("|"," ")
str1.split()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM