Someone has already given you a Regex that will work, but I wanted to
show you what happened with the regex you provided.

What I see in your regex is:

/^
Start of the line

[A-Z a-z]
One uppercase letter, space, or lowercase letter.
It looks like you're trying to include two character classes in one set
of brackets.  You have to separate the character classes to get what you
want: [A-Z][a-z]+ would work.

\s+
One or more spaces

[A-Z a-z]{1,15}
One to fifteen uppercase letters, spaces, or lowercase letters

$/
And then the end of the line, possibly including a \n character






You might want to look at the YAPE::Regex::Explain module.  If you're
not sure what a regex is doing, it will break it down for you.


Here's what YAPE::Regex::Explain had to say about your Regex.


(?-imsx:/^[A-Z a-z]\s+[A-Z a-z]{1,15}$/)

matches as follows:

NODE                     EXPLANATION
----------------------------------------------------------------------
(?-imsx:                 group, but do not capture (case-sensitive)
                         (with ^ and $ matching normally) (with . not
                         matching \n) (matching whitespace and #
                         normally):
----------------------------------------------------------------------
  /                        '/'
----------------------------------------------------------------------
  ^                        the beginning of the string
----------------------------------------------------------------------
  [A-Z a-z]                any character of: 'A' to 'Z', ' ', 'a' to
                           'z'
----------------------------------------------------------------------
  \s+                      whitespace (\n, \r, \t, \f, and " ") (1 or
                           more times (matching the most amount
                           possible))
----------------------------------------------------------------------
  [A-Z a-z]{1,15}          any character of: 'A' to 'Z', ' ', 'a' to
                           'z' (between 1 and 15 times (matching the
                           most amount possible))
----------------------------------------------------------------------
  $                        before an optional \n, and the end of the
                           string
----------------------------------------------------------------------
  /                        '/'
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------




-----Original Message-----
From: Gerald Wheeler [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 14, 2006 12:04 PM
To: beginners@perl.org
Subject: regexpressions help

I am trying to allow input of a person's first and last name in one form
field, nothing more, nothing less

There should be only one uppercase A-Z character followed by one or
more lowercase a-z characters followed by one space followed by one
uppercase A-Z character followed by one or more lowercase a-z
characters, nothing more.

have tried this which does not work:  /^[A-Z a-z]\s+[A-Z a-z]{1,15}$/

Thanks.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to