简体   繁体   中英

Split string using regex in python

I'm trying to split the string in to two strings

 INPUT: "ASSO|ASSOCS|AS|ASSOCIATES/ASSOC/"

OUTPUT: "ASSO|ASSOCS|AS|ASSOCIATES","ASSOC"

Tried : I tried removing the the last character " /" first and replaced the other with "," . Wanted to know can we do this both steps in once using regex

str=str.replace(/\/$/, "")
str=str.replace(\/,",")

If you are "trying to split the string in to two strings", then you could do

s = "ASSO|ASSOCS|AS|ASSOCIATES/ASSOC/"
s1, s2, _ = s.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