[Chicago] Basic Regex Question

Carl Karsten carl at personnelware.com
Sat Feb 21 17:47:56 CET 2009


Chris McAvoy wrote:
> Hi All,
> 
> I have the following regex:
> album_regex = re.compile(r'(?P<artist>.*)\s-\s(?P<album>.*)\((?P<label>.*)\)')
> 
> Which matches things like: John Coltrane - Interstellar Space
> (Impulse ASD 9277)
> artist: John Coltrane
> album: Interstellar Space
> label: Impulse ASD 9277
> 
> very well, but has troubles on lines like:
> 
> John Coltrane - Coltrane In Japan  (Impulse (J) IMR 9036C)
> artist: John Coltrane
> album: Coltrane In Japan  (Impulse
> label: J) IMR 9036C
> 
> I get the feeling that there's a simple switch to say "get the first
> and last parens", but I'm having trouble with it, as I'm impatient,
> and not so hot at regex's.
> 
> Help me ChiPy, you're my only hope.

can you give me a few lines of code that print the the Bs in "AAA(BBB)CCC"

I am hot for regex, but not so hot with the python re module.

Help me, help you.

Carl K






More information about the Chicago mailing list