repeating a section of a regular expression?


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 matching a certain pattern 12 or 13 times.

The pattern I want to repeat is


This is the regular expression (shortened)


Is there a way to match a pattern a set number of times without copy pasting like this? Each of those sections correspond to data columns, all of which I need. I'm using Python by the way. Thanks!

1/12/2012 10:38:41 PM

Accepted Answer

How about using:


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

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

is probably what you really want.

1/12/2012 10:41:11 PM


The {n} is a "repeat n times"

if you want "12 - 13" times,


if you want "12+" times,


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow