Actually... for simplicities sake drop the + modifier and just negate the 
result. A read of 'Mastering Algorithms with Perl' will also reveal that 
for static string matches you get better performance (not that I've 
benchmarked it myself, I just trust the text) from index().

$string !~ /\s/
not $string =~ /\s/
-1 == index $string, ' '  # faster than a regex, only works for the 
literal value ' '. \s matches more white-space characters.

Josh




"$Bill Luebkert" <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
07/18/2002 07:14 AM

 
        To:     "Martin, Greg \(CSC\)" <[EMAIL PROTECTED]>
        cc:     "'[EMAIL PROTECTED]'" 
<[EMAIL PROTECTED]>
        Subject:        Re: Regex - matching a string with no spaces


Martin, Greg (CSC) wrote:
> If there's a better place to post this, please let me know.
> 
> I'm trying to write a module that looks at mailbox names and excludes
> non-people.  I use regex to match specific strings which I no are not
> people, but I'd like a generic regex to match strings which have no 
spaces
> (a common indicator of non-human mailboxes).  This should be easy and 
I've
> tried several things but just can't get through the mental block
> 
> My feeble tries:
> [^\s]  (matches every non-space character)
> [\s{0}]  (0 occurrences of set \s - excludes everything apparently)
> \s{0}   (0 occurrences of \s - same thing)

If I understand your question (you really should post a code snippet):

if ($str =~ /\s+/) {
                 # string has whitespace
}

# or for just spaces/blanks rather than ' ', \t, \n try:  if ($str =~ / 
+/) {
# \s means whitespace not space/blank

-- 
   ,-/-  __      _  _         $Bill Luebkert   ICQ=162126130
  (_/   /  )    // //       DBE Collectibles   Mailto:[EMAIL PROTECTED]
   / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to