On Nov 9, 1:53Â pm, pinkisntwell <pinkisntw...@gmail.com> wrote: > How can I make a regular expression that will match every occurrence > of a group and return each occurrence as a group match? For example, > for a string "-c-c-c-c-c", how can I make a regex which will return a > group match for each occurrence of "-c"?
As well as what Diez has said, unless you absolutely want regexp's, and by the sounds of it I'm guessing you may be after something more flexible: what about the pyparsing module [1]. It handles your situation quite nicely. >>> import pyparsing >>> parser = pyparsing.ZeroOrMore('-c') >>> parser.parseString('-c-c-c-c-c-c') (['-c', '-c', '-c', '-c', '-c', '-c'], {}) hth, Jon. [1] http://pyparsing.wikispaces.com/ -- http://mail.python.org/mailman/listinfo/python-list