Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Two-dimensional match/regex?

by rob_au (Abbot)
on May 22, 2002 at 10:31 UTC ( #168391=note: print w/replies, xml ) Need Help??

in reply to Two-dimensional match/regex?

I'm sure I must be missing the problem at hand to a certain extent, but have you looked at the m option for regular expression matches which allows for multi-line matches. For example, the regular expression match for the sample match given may look something like the following - \/\^\\\n.+C - to match:

  • the character sequence /^\,
  • a new-line character (\n),
  • one or more characters (.+), and,
  • the character, C.

This regular expression can be used in conjunction with the multi-line match option for regular expressions as follows, similar to how one would use the case-insensitive option for regular expressions:

if ($target =~ /\/\^\\\n.+C/m) { }

For further information see perlman:perlre


Update - This regular expression has been tested and does work. The effectiveness of a multi-line regular expression match can be tailored within the regular expression itself - That is, the more specific which you make your regular expression, the greater the specificity of the match, but as with all targeted solutions, there is a trade-off between sensitivity and specificity.


Replies are listed 'Best First'.
Re: Re: Two-dimensional match/regex?
by osfameron (Hermit) on May 22, 2002 at 10:44 UTC
    I think the above won't work as such, because it might find false matches (e.g. where the second line isn't aligned with the first.)

    But, I could find the first line and then generate a multi-line regex with the rest of the search string, using /m as you suggest: something like   /^.{$pos}$string1.*\n^.{$pos}$string2.*/m to make it search only at the right position...
    (Apologies for dodgy regex, not tested and probably wrong).

    thanks for the tip, I should have thought of that already!


      You could always surround the terms which lie between the stuff you want to match with (), and check that $1, $2, etc. are the same length as the first, second, etc. line matched.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2021-10-27 05:40 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (91 votes). Check out past polls.