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

Either I misunderstand the spec, or your solution fails:

#!/usr/bin/perl use strict; use warnings; my @tests = ("\% only 1 profile is allowed\n\n", # Should fail "\n\n", # Should pass "", # Should pass ); my $regex = "(?!.*\\S)"; for (@tests) { print $_ =~ qr{$regex}ms ? "$_\n REGEX MATCHED\n" : "$_\n FAILED!\ +n"; }

Like with the bad OP proposal, your regex passes for all cases.

Update: Fixed mistake in posted test, though it does not change the result. See below for corrected regular expression.

Replies are listed 'Best First'.
Re^3: Multiline match for empty string
by ikegami (Patriarch) on Aug 05, 2010 at 23:00 UTC

    I forgot to anchor. Should be

    "\\A(?!.*[^\n])" or "\\A(?!.*\\S)"

    Of course, the following are much simpler:

    "\\A[^\n]*\\z" or "\\A\\s*\\z"

    By the way, your test is wrong. You never actually attempt to match.