Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Is there a regex match for an empty string ?

by GrandFather (Saint)
on Mar 19, 2012 at 23:21 UTC ( [id://960492]=note: print w/replies, xml ) Need Help??


in reply to Is there a regex match for an empty string ?

Define "empty string". Consider:

use strict; use warnings; for my $str ('', ' ', '\0', "\n", undef) { print "matched '$str'\n" if $str =~ /\A\z/; }

Prints:

matched '' Use of uninitialized value $str in pattern match (m//) at C:\Users\Pet +er\Delme~~\PerlScratch\noname.pl line 8. matched '' Use of uninitialized value $str in concatenation (.) or string at C:\U +sers\Peter\Delme~~\PerlScratch\noname.pl line 8.

length may be a better test than using a regex, and clearer to the maintenance programmer.

True laziness is hard work

Replies are listed 'Best First'.
Re^2: Is there a regex match for an empty string ?
by palkia (Monk) on Mar 19, 2012 at 23:43 UTC
    I agree with you that the "length" function is the better solution,
    but I'm bounded by a generalized format, which requires regex.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://960492]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-18 14:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found