in reply to Re^2: Multiline match for empty string
in thread Multiline match for empty string
my $regex = q|(??{'\s{' . length($tests) . '}'})|;
This requires you to include use re 'eval'; at some point in scope. It also requires that the name of of the variable being tested is literally $tests - if not, you need to modify the string accordingly.
How it works:
The expression uses Perl code executed at matching time - see (??{ code }) in perlre. The string literal stored in $regex is (??{'\s{' . length($tests) . '}'}). When the regular expression is executed, Perl concatenates '\s{', the length of the variable $tests and '}'. The resulting regular expression requires that the string in question match exactly as many whitespace characters as there are characters in the string, i.e. contain only whitespace. You should also note that this opens up some security holes in Perl, as discussed in (??{ code }) and in A bit of magic: executing Perl code in a regular expression from perlretut.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Multiline match for empty string
by josh803316 (Beadle) on Aug 05, 2010 at 18:25 UTC |