Python-get string between to characters

后端 未结 4 433
悲哀的现实
悲哀的现实 2021-01-29 14:07

I need to one give me the string between ~ and ^.
I have a string like this:

~~~~ ABC ^ DEF ^ HGK > LMN ^  

I

4条回答
  •  粉色の甜心
    2021-01-29 14:34

    here is my solution:

    your input:

    In [12]: target = ' ~~~~ ABC ^ DEF ^ HGK > LMN ^  '
    

    replace all the symbols or delimiters with ' ' and split the result

    In [13]: b = re.sub(r'[^\w]', ' ', target).split()
    
    In [14]: b
    Out[14]: ['ABC', 'DEF', 'HGK', 'LMN']
    

提交回复
热议问题