So you're saying you want to match 'hijklmnop', with or without any amount of whitespace appearing between any of the characters, including the possibility of newlines?
use strict; use warnings; my $string = <<HERE; abcdefg hijk lm no pqr stu vwkyz HERE my $find = 'hijklmnop'; my $re = join '\s*', split( //, $find ); print "Matched!\n" if $string =~ $re;
In this situation it's not necessary to use the /s switch, but in some situations, where you're trying to match a pattern across multiple lines, you'll want to use the /s regexp modifier. It causes '.' to match any character including newlines. In the example above, however, \s is used, and that matches whitespace including newlines. This and more is discussed in perlre.
Ultimately, it seems pretty awkward building up a regexp with \s* between each character you're trying to match. It might be wiser to preprocess your text, eliminating newlines, or insignificant whitespace.
Dave
In reply to Re: Matching regex on multilines
by davido
in thread Matching regex on multilines
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |