in reply to Re^2: Multiline match for empty string
in thread Multiline match for empty string

It's probably easier and cleaner to just write a one-off test rather than working within this fixed framework, but you could use this to check if your test string contains only whitespace:

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
    Thanks for the help!! The system is a complete automation application which allows users to enter expected results and to allow the step to pass/fail based on the comparison of the expected result vs the actual result. I've allowed the inclusion of regular expressions in the expected result but I can't change the matching logic on the fly so I need something that will match multi-line and single line as well as empty text. I added some logic from the original suggestion so that If the expected result is an empty string I do the negative match and for all other strings I proceed with the normal multiline match. Thank you again for the help!!!