CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Stumped by Regex

 



stupeas
Novice

Dec 6, 2006, 6:11 AM

Post #1 of 2 (385 views)
Stumped by Regex Can't Post

Hello, Hope someone can help.
I need to find a regex to take a surname (any surname) from a form with <STDIN>,
It must take "double-barrel" names into account (ie those with a space in the middle), but the whole string must be no longer than 20 characters. It must start with a letter and end with a letter with the space (or no space) appearing somewhere in the middle. It must also cater for normal single word surnames.

This is what i have so far (but doesnt limit to 20 characters)

m/^([a-zA-Z]\s?[a-zA-Z]?){1,20}$/

I bet this is simple but for the life of me i cant figure out the regex i need.

TIA


kencl
User

Dec 16, 2006, 2:20 PM

Post #2 of 2 (372 views)
Re: [stupeas] Stumped by Regex [In reply to] Can't Post

You're on the right track. There are 2 problems with what you have. The first is that the part which matches alphabetical characters only matches 1 character the first time, and 0 or 1 characters the second time. The second is that you are allowing a space character to possibly be the last character.

Here is what you are after:

Code
m/^([a-zA-Z]+(\s[a-zA-Z]+)?){1,20}\z/


>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives