Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: regexp over multiple lines

by JavaFan (Canon)
on Aug 03, 2011 at 07:43 UTC ( [id://918188]=note: print w/replies, xml ) Need Help??


in reply to Re: regexp over multiple lines
in thread regexp over multiple lines

Use the /m modifier. This will treat the string as multiple lines, allowing you to use \n characters as part of your regexp.
Bullshit.

You don't need any modifier to use \n in your regexp. The /m modifier will change the meaning of ^ and $, irrelevant for the OP. He may need the /s modifier, which makes the dot match a newline.

Replies are listed 'Best First'.
Re^3: regexp over multiple lines
by liverpaul (Novice) on Aug 03, 2011 at 08:08 UTC

    Thanks for the reply :-)

    So, if my file looked like this:

    line1data line2data line3data line4data <homePrice> 1.91</homePrice> line7data line8data line9data

    ...and I was forced to process the file line by line in a for loop, what regexp would I use (if any are possible) to extract the value of 1.91 by matching both lines?

      You're solving the wrong problem. It's not a magical regexp you need. It's the "process the file line by line" that needs changing.

        Yeah, I'm beginning to see that now. Unfortunately there's a lot of code built on the incorrect foundation of line-by-line.

        I'm eventually going to change to "slurping", but for now I'm going try to "force" a messy solution. From my understanding I think I can do this by concatenating 3 or 4 lines. Maybe it will work, time will tell.

Re^3: regexp over multiple lines
by blindluke (Hermit) on Aug 03, 2011 at 08:17 UTC

    Thanks for pointing that out, it seems I got it all wrong. Apologies to liverpaul, if my response was misleading.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2024-04-23 08:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found