python regex for repeating string

后端 未结 4 1540
南方客
南方客 2021-01-07 04:31

I am wanting to verify and then parse this string (in quotes):

string = \"start: c12354, c3456, 34526; other stuff that I don\'t care about\"
//Note that som         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-07 05:08

    import re
    
    sstr = re.compile(r'start:([^;]*);')
    slst = re.compile(r'(?:c?)(\d+)')
    
    mystr = "start: c12354, c3456, 34526; other stuff that I don't care about"
    match = re.match(sstr, mystr)
    if match:
        res = re.findall(slst, match.group(0))
    

    results in

    ['12354', '3456', '34526']
    

提交回复
热议问题