Product code looks like abcd2343, what to split by letters and numbers

后端 未结 6 923
不知归路
不知归路 2020-12-02 18:34

I have a list of product codes in a text file, on each like is the product code that looks like:

abcd2343 abw34324 abc3243-23A

6条回答
  •  眼角桃花
    2020-12-02 19:05

    import re
    
    m = re.match(r"(?P[a-zA-Z]+)(?P.+)$",input)
    
    m.group('letters')
    m.group('the_rest')
    

    This covers your corner case of abc3243-23A and will output abc for the letters group and 3243-23A for the_rest

    Since you said they are all on individual lines you'll obviously need to put a line at a time in input

提交回复
热议问题