Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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.

Replies are listed 'Best First'.
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;


      >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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://979072]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2018-03-21 23:39 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (272 votes). Check out past polls.