How to extract the substring between two markers?

前端 未结 18 2682
慢半拍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条回答
  •  忘掉有多难
    2020-11-22 06:11

    Another way of doing it is using lists (supposing the substring you are looking for is made of numbers, only) :

    string = 'gfgfdAAA1234ZZZuijjk'
    numbersList = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    output = []
    
    for char in string:
        if char in numbersList: output.append(char)
    
    print(f"output: {''.join(output)}")
    ### output: 1234
    

提交回复
热议问题