Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Multiline pattern matching

by blue_cowdawg (Monsignor)
on May 21, 2001 at 18:22 UTC ( #81973=note: print w/replies, xml ) Need Help??

in reply to Multiline pattern matching

Base Assumption: Your text you are trying to match is somehow in one single variable.

$str =~ m/foo\{(.*)\}\;/;

$1 is now going to contain everything between the curly braces. The flaw I see in my own pattern matching is the fact that if you have another "};" along the way you might not have what you are after.

Then again.. you were pretty vague about your specifications... ;-)

Peter L. Berghold --- Peter@Berghold.Net
"Those who fail to learn from history are condemned to repeat it."

Replies are listed 'Best First'.
Re: Re: Multiline pattern matching
by alfie (Pilgrim) on May 21, 2001 at 18:28 UTC
    Sorry, blue_cowdawg, you do a common mistake: You used dot star - please read Death to Dot Star! which explains why you should never ever use it :-)
    use signature; signature(" So long\nAlfie");

      Your Death to Dot Star post is rather convincing!

      I like merlyn's comment concerning inching along though. If I really had to write something to parse foo { ... }; I'd probably use that.

      What I find really intriguing however is the original question posed however vague. Given a Perl'ish structure of text where you have a symbol followed by a open curly brace followed by more text with possibly more curly braces (open and closed) how do you go about matching the right pair?

      My first instinct would be to look towards some sort of recursive parser and not a regex. What are your thoughts?

      Peter L. Berghold --- Peter@Berghold.Net
      "Those who fail to learn from history are condemned to repeat it."

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2022-05-26 23:52 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (94 votes). Check out past polls.