2021年1月27日星期三

How to split string by outer parentheses ignoring nested parentheses - Python

I want to split a string by the outer parentheses ignoring all nested parentheses.

E.g:

sentence = "I am going (to the (supermarket)) but I (forgot) my wallet"  

Goal is to get:

["I am going", "to the (supermarket)","but I", "forgot", "my wallet"]  
https://stackoverflow.com/questions/65927340/how-to-split-string-by-outer-parentheses-ignoring-nested-parentheses-python January 28, 2021 at 05:00AM

没有评论:

发表评论