Help: Arbitrary number of groups in regex

Jean-Philippe Côté cotej at crt.umontreal.ca
Fri Aug 9 00:40:00 CEST 2002


"Carl Banks" <imbosol at vt.edu> wrote in message
news:aiun6i$ap1$2 at solaris.cc.vt.edu...
> "Jean-Philippe C?t?" wrote:
> > The way I undestand "(\w)*" is <<match a single alphanumeric
> > character, put in into a group, return that group and repeat as
> > long a you can>>, but that doesn't work:
> >>>> m = re.match("(\w)*", "abcde")
> >>>> m.groups()
> > ('e',)
> >>>>
> >
> > Does anybody know what the PATTERN should be ?
>
> I don't believe it's possible.  Perhaps it should be.  If all you want
> to do is split a string into a sequence of characters, just do this:
>
> >>> tuple("abcde")
> ('a', 'b', 'c', 'd', 'e')
>

I'm starting to think it's impossible too. Perhaps I oversimplified
the problem in my. What I have is actually an arbitrary number
or comma separated values, each of which can be
composed of letters or numbers. I don't know the number in
advance. For instance, I might have the following input:

" FL234,  MK434,  9743"

I've tried to write a regex pattern which could return me each value
in a separate group, but I believe I have to 'split' the string first
and then parse each value separately.

J-P




> --
> CARL BANKS
> http://www.aerojockey.com


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.381 / Virus Database: 214 - Release Date: 8/2/2002





More information about the Python-list mailing list