[Chicago] Basic Regex Question
Michael Urman
murman at gmail.com
Sat Feb 21 17:48:29 CET 2009
On Sat, Feb 21, 2009 at 10:23, Chris McAvoy <chris.mcavoy at gmail.com> wrote:
> Hi All,
>
> I have the following regex:
> album_regex = re.compile(r'(?P<artist>.*)\s-\s(?P<album>.*)\((?P<label>.*)\)')
Perhaps adjust the middle part to (?P<album>.*?) to make it non-greedy.
> 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.
Nope there's not; that's not how regexs work. However this case is
simple enough it just might be doable. Instead of each part grabbing
as much as possible such that later parts match, you can make some
parts grab as little as possible such that later parts match.
--
Michael Urman
More information about the Chicago
mailing list