Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Two-dimensional match/regex?

by rob_au (Abbot)
on May 22, 2002 at 10:31 UTC ( [id://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!

    Cheerio!
    Osfameron
    http://osfameron.perlmonk.org/chickenman/

      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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-09-17 08:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (22 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.