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

Time:06-29

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']

CodePudding user response:

maybe u can try using Regular expression

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

CodePudding user response:

Use below code , it should work

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