Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: String contents

by perlyr (Novice)
on Jun 29, 2012 at 08:21 UTC ( [id://979070]=note: print w/replies, xml ) Need Help??


in reply to Re: String contents
in thread String contents

Yes, I was trying to extract a string from a textfile, but couldn't parse it correctly. Here is part of the file:
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
Here is my regex:
/^\s*(\w+),\s*(\w+ \w+)(.+?\s*LLP)$/m;

I wanted to extract: Melville, New York, /s/KPMG LLP

Any suggestions?

Replies are listed 'Best First'.
Re^3: String contents
by GrandFather (Saint) on Jun 29, 2012 at 08:30 UTC
    Any suggestions?

    Yes. Take note of my sig. I'm not going to work hard to decode your node because you are too lazy to read the instructions about using a little mark up so that your node is nicely formatted.

    If you had expended just a little time and effort (maybe five minutes) to explain your problem well and formatted your node nicely you'd have had an answer in 15 minutes and be an hour ahead.

    True laziness is hard work
Re^3: String contents
by moritz (Cardinal) on Jun 29, 2012 at 08:25 UTC
      you are right, the anchor $ shouldn't be there. But I only extracted "New" instead of "New York"
      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
Re^3: String contents
by perlyr (Novice) on Jun 29, 2012 at 08:26 UTC

    Melville, New York /s/KPMG LLP

    September 26, 2001

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-25 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found