Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Stumped by regex

by JediWizard (Deacon)
on Dec 06, 2006 at 14:55 UTC ( #588096=note: print w/replies, xml ) Need Help??


in reply to Stumped by regex

Something like this? (It limits to strings no longer than twenty characters, nothing but letters and an optional space).

m/^(?=.{1,20}\Z)[a-z]+(?:\s[a-z]+)?$/i

In the end, however, I think you'd be better off using length to check the string's length outside the regex. Hope this is helpful.


They say that time changes things, but you actually have to change them yourself.

—Andy Warhol

Replies are listed 'Best First'.
Re^2: Stumped by regex
by bsdz (Friar) on Dec 06, 2006 at 15:40 UTC
    Except: -
    'David George' =~ m/^(?=.{1,20}\Z)[a-z]+(?:\s[a-z]+)?$/i;
    does not return 'George'?

      I guess I didn't realize he needed it too... But that is only a two character change.


      They say that time changes things, but you actually have to change them yourself.

      —Andy Warhol

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2021-06-15 14:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (72 votes). Check out past polls.

    Notices?