in reply to Matching regex on multilines

To highlight something davido mentions in passing, if the white space is insignicant to your pattern, that is, it doesn't matter at all and actively impedes your processing, why not simply remove the white space, then match as usual.

Replies are listed 'Best First'.
Re^2: Matching regex on multilines
by dwilson@d7net (Initiate) on Nov 15, 2004 at 16:56 UTC
    As davido and BUU referred to here's an example...
    If your input file isn't too big you could do something like this...
    #!/usr/bin/perl -W use strict; my $string = <<HERE; abc defg hijk lm no pqr stu vwkyz HERE my $find = "hijklmnop"; # get a copy to avoid modifying orig $_ = $string; # remove all spaces s/\s//gs; # note the /s that davido referred to print "Matched!\n" if $_ =~ $find; # to see what the subst did. print $_;
    Not sure which is more efficient though...

    Also, it seems like you could do something like this, never modifying the orig string...
    But I couldn't get it to work. May the gurus can help...
    my $result; $_ = $string ($result) = /((\w+(?=\s*))+)/s; # ((1 char) followed by # (zero or more whitespace[don't return]) # match one or more)