Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: String contents

by moritz (Cardinal)
on Jun 29, 2012 at 08:25 UTC ( #979072=note: print w/ replies, xml ) Need Help??


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

Your regex expects the end of the line directly after the LLP, but the string goes on. So remove that $ in the regex.


Comment on Re^3: String contents
Download Code
Re^4: String contents
by perlyr (Novice) on Jun 29, 2012 at 08:32 UTC
    you are right, the anchor $ shouldn't be there. But I only extracted "New" instead of "New York"
Re^4: String contents
by perlyr (Novice) on Jun 29, 2012 at 08:43 UTC
    Here is the code again:
    /^\s*(\w+),\s*(\w+ \w+)(.+?\s*LLP)/m
    why did I extract "New" instead of "New York"?
      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
        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;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://979072]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-07-12 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (239 votes), past polls