Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Regex Help

by kennethk (Monsignor)
on Jun 12, 2012 at 16:41 UTC ( #975846=note: print w/ replies, xml ) Need Help??


in reply to Regex Help

This is definitely getting into TIMTOWTDI territory. If you suck in the entire input using a slurp (see $/), then your existing regular expression would work.

Rather than using the character class [\s\S], I think intent would be more obvious using . combined with the s modifier: if ($_ =~ /start(.+?)end/si)

I would probably also add word boundaries around your start and end, so you don't get false positives from words like 'send': if ($_ =~ /\bstart\b(.+?)\bend\b/si) Even better, if you know that start and end are on lines by themselves, use the m modifier to say as much: if ($_ =~ /^start\s*\n(.+?)^end\s*$/smi) Regular expressions play best when they are tightly constrained.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re: Regex Help
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2014-08-28 01:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (254 votes), past polls