On Sat, Jun 19, 2010 at 20:21, Jim Gibson <jimsgib...@gmail.com> wrote: snip >> 'Hughes, D 2-0, O'Flaherty 2-0, Moylan 1-1' snip > The "clever" way is to use a regular expression that covers all of the > possible cases. Here is one that works for your sample string: > > $x = q(Hughes, D 2-0, O'Flaherty 2-0, Moylan 1-1); > while( $x =~ m{ \s* ([\w,\s]+) \s+ (\d+-\d+) \s* (,|\z) }gx ) { > print "$1: $2\n"; > } snip
Don't use \d, it doesn't mean [0-9] in Perl 5.8 and onward (it now matches any Unicode digit character). The important part here is that /[0-9]+-[0-9]+(?:,|\z)/ will match the end of the string we want. It is actually harmful to try to specify what comes before it. For instance, your regex won't match "O'Flaherty". When you don't need to verify and you don't need to anchor the regex, it is better to be as generic as possible. In this case, /.*?/ will match the runner's name regardless of how it is formatted. Names are particularly troublesome things. Another fairly common issue is hyphenated names like "Foo-Bar". -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/