repeating a section of a regular expression?

前端 未结 2 691
死守一世寂寞
死守一世寂寞 2020-12-20 11:26

I\'m having to parse a text dump of a spreadsheet. I have a regular expression that correctly parses each line of the data, but it\'s rather long. It\'s basically just mat

2条回答
  •  时光取名叫无心
    2020-12-20 12:01

    How about using:

    [x.group() for x in re.finditer(r'(\s+(\w*\.*\w*);)*', text)]
    

    Did you find the findall method yet? Or consider splitting at ;?

    map(lambda x: x.strip(), s.split(";"))
    

    is probably what you really want.

提交回复
热议问题