How to extract the substring between two markers?

前端 未结 18 2332
慢半拍i
慢半拍i 2020-11-22 06:02

Let\'s say I have a string \'gfgfdAAA1234ZZZuijjk\' and I want to extract just the \'1234\' part.

I only know what will be the few characte

18条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 06:14

    >>> s = 'gfgfdAAA1234ZZZuijjk'
    >>> start = s.find('AAA') + 3
    >>> end = s.find('ZZZ', start)
    >>> s[start:end]
    '1234'
    

    Then you can use regexps with the re module as well, if you want, but that's not necessary in your case.

提交回复
热议问题