in reply to Explaining a Regular Expression

It's an expression which always matches, i.e. the else branch won't be executed. UPDATE: What I have written, was non-sense. I should have said: It is an expression which matches iff the line contains only white space.

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^2: Explaining a Regular Expression
by Fletch (Bishop) on Jul 06, 2010 at 15:18 UTC
    $ perl -le '$_ = "blort";if (/^\s*$/) { print "always matches" } else +{ print "Orly?" }' Orly?

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re^2: Explaining a Regular Expression
by zek152 (Pilgrim) on Jul 06, 2010 at 15:14 UTC

    This expression does not always match. The presence of ^ and $ impose conditions that cause it to not always match. The code below shows a simple case which does not match

    $data = "This doesn't match\n"; if ($data =~ /^\s*$/) { print "$data Matches\n"; } else { print "$data Does not match\n"; } #OUTPUT #This doesn't match # Does not match
      Sorry, this was probably the most stupid answer I have ever given in this forum. I should have looked closer - will update my node.

      -- 
      Ronald Fischer <ynnor@mm.st>