in reply to Re^4: String contents
in thread String contents

why did I extract "New" instead of "New York"?

Can't tell because you don't actually show the code that generated the result you claim. The regex works as you seem to expect for me:

use strict; use warnings; my $str = <<STR; ended June 30, 2001 in conformity with accounting principles generall +y accepted in the United States of America. Also in our opinion, the related fina +ncial statement schedule, when considered in relation to the basic consolida +ted financial statements taken as a whole, presents fairly, in all materia +l respects, the information set forth therein. Melville, New York /s/KPMG LLP September 26, 2001 STR my @matches = $str =~ /^\s*(\w+),\s*(\w+ \w+)(.+?\s*LLP)$/m; print ">$_<\n" for @matches;

Prints:

>Melville< >New York< > /s/KPMG LLP<
True laziness is hard work

Replies are listed 'Best First'.
Re^6: String contents
by perlyr (Novice) on Jun 29, 2012 at 09:20 UTC
    Yes, you are right. This code works now. But when I was trying to generalize this regex, it failed. Here is the new code:
    =~ /^\s*(\w+|\w+ \w+|\w+ \w+ \w+),\s*(\w+|\w+ \w+|\w+ \w+ \w+)(.+?\s*L +LP)$/m;