简体   繁体   中英

Use regular expression to escape a special character " which is also used as delimiter

" is used as a delimiter for each substring but also used as a special character inside each substring as /"

Is there an way to separate each substring based on the " delimiter with each substring containing \\" if any.

For example, String is:

"we don't care about \\"you\\" " "I don't care \\" \\"about." "I care about you"

Output:

"we don't care about \\"you\\"

"I don't care \\" \\"about."

"I care about you"

I tried:

re.findall(r'(?:\"(.*?)\")', string)

but I am unable to escape through \\".

Thanks a lot for your help.

The easy way might be:

s = '"HI in \"blah\"" "seconds" "\"thi\"rd"'

s[1:-1].split('" "')
# ['HI in "blah"', 'seconds', '"thi"rd']

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