Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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.

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;

      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?
[stevieb]: yeah, I snowshoe a fair amount in the mountains. I also use spikes similar to these very often as well
[perldigious]: Discipulus: alternate link
[stevieb]: LOL you can easily replace "Helsinki" with "Alberta"
[perldigious]: I used to live at the top of a very steep hill stevieb, I can relate to the video. Literally used to have to build up momentum and try to force my vehicle to make it up the hill to park in my driveway properly... didn't always make it.
[choroba]: Why don't they use tire chains?
[perldigious]: First snow, probably not prepared right away choroba.
[stevieb]: it's Quebec... they do weird stuff there :) In the mountains, it is *mandatory* for trucks to use tire chains. Many passenger vehicles do as well (but it's not mandatory for them)
[perldigious]: That stuff can hit fast... like what we just got where I'm at. Saw a few people who had slid OUT of the roundabout I have to drive through to get to work, not used to the ice yet, take awhile to get the hang of it again and make vehicle adjustments.
[stevieb]: man, when the roads are glare ice, I don't even bother going to work or out... unless I absolutely have to, or was already out in the first place

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2016-12-06 16:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (112 votes). Check out past polls.