Regex question

darrell dgallion1 at yahoo.com
Wed Sep 18 22:37:15 EDT 2002


s="Name:AAA,BBB,CCC"
print re.split(":|,", s)
print re.findall("[^:,]+", s)

['Name', 'AAA', 'BBB', 'CCC']
['Name', 'AAA', 'BBB', 'CCC']

--Darrell

Eric Arnold wrote:

> Hi folks,
> 
> I'm trying to figure out why this is not working, and wonder if there are
> any regexperts out there who can give me a pointer.
> 
> The string I'm capturing is as follows:
> 
> Name:AAA,BBB,CCC
> 
> where I'd like to extract the following data:
> 
> <eventName>: Name
> <eventParam 1>: AAA
> <eventParam 2>: BBB
> <eventParam 3>: CCC
> 
> this is the regular expression I wrote to do so:
> 
> (?<eventName>.*):(?<eventParam>([^,]*(?=,))|((?<=,)[^,]*))+
> 
> I tried it with the (?<=,) as another (?=,) too, but no luck.  I imagine
> that the problem is that when the (?=) is used once, it can't be used with
> the second group, but I don't know a way around that.
> 
> Thanks!
> 
> Eric




More information about the Python-list mailing list