python regex for repeating string

后端 未结 4 1499
南方客
南方客 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:23

    You could use the standard string tools, which are pretty much always more readable.

    s = "start: c12354, c3456, 34526;"

    s.startswith("start:") # returns a boolean if it starts with this string

    s.endswith(";") # returns a boolean if it ends with this string

    s[6:-1].split(', ') # will give you a list of tokens separated by the string ", "

提交回复
热议问题