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:00

    In Python, this isn’t possible with a single regular expression: each capture of a group overrides the last capture of that same group (in .NET, this would actually be possible since the engine distinguishes between captures and groups).

    Your easiest solution is to first extract the part between start: and ; and then using a regular expression to return all matches, not just a single match, using re.findall('c?[0-9]+', text).

提交回复
热议问题