On Aug 31, agc said:

>so I would like to know wich woud be the reg exp for a case like that.... 
>where are examples? fro a beguinner? can any one give me a hand with 
>this? cheers

There are several Perl documents on regexes:

  perlrequick
  perlretut
  perlre

Looking at them in that order should be optimal.  They have examples, of
course.

As for your specific example, once you know the basics of regexes, it is
simply a matter of understanding your OWN need.

If you need to match a string made up entirely of underscores, you need
to:

  1. start looking at the beginning of the string  ^
  2. look for 1 or more underscores in a row       _+
  3. and then be at the end of the string          $

  if ($str =~ /^_+$/) { ... }

Or, you could:

  1. make sure there is not a non-underscore character  [^_]
  2. make sure there is at least ONE underscore         _

  if ($str !~ /[^_]/ and $str =~ /_/) { ... }

These two approaches produce the same end result (you find out if the
string is made up entirely of underscores) but they are written
differently.  The second approach can even just use ONE regex.  We're
testing to see if there IS an underscore, just to make sure $str isn't an
empty string (because an empty string doesn't have any non-underscores in
it).  So we can test the length of the string, and then see if there are
any non-underscores:

  if (length($str) and $str !~ /[^_]/) { ... }

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to