2020年12月31日星期四

How to get String between a particular character in Python

If I have a String like this

s = 'a{ b{ cd }e{ fg } } h{ i{ jk }l{ mn }}'  

Is there a way to get the following output

a h  

I have tried the following regex

p = re.sub(r"\.*?\{(.*)\}.*",'',s)  

However the output comes as

a  

Is there any changes I can do to the regex to get my desired output? The issue the output comes like this is that the API is handled by a different comp, so for now I have to handle it.

https://stackoverflow.com/questions/65527110/how-to-get-string-between-a-particular-character-in-python January 01, 2021 at 11:30AM

没有评论:

发表评论