Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: pattern matching

by mkmcconn (Chaplain)
on Jan 10, 2002 at 03:03 UTC ( #137604=note: print w/replies, xml ) Need Help??


in reply to pattern matching

dmmiller2k is right.
You also want to be sure that the 'text' that you are reading is examined as a single string, by your matching pattern (not one line at a time).
Then the regex is pretty simple (but note the /s operator is added, as dmmiller2k advised).
#!/usr/bin/perl -w use strict; #examine DATA as a single string. $/ = ''; while (<DATA>){ #'.' will match \n with the /s operator if ( m/if.+else/s ){ s/{//; s/}//; } print; } __END__ if (c=e) { #// delete this curly brace call pgme; call pgmd; } else { call pgmd; #// keep these curly braces call pgmc; } if (c=e) { #// delete this curly brace call pgme; call pgmd; } else { call pgmd; #// keep these curly braces call pgmc; }

mkmcconn
update please note that this regex example is
for illustration only - it's easily broken and the reason
it appears to work is because of the structure of the data
example.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2023-02-05 23:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (33 votes). Check out past polls.

    Notices?