Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: regex: only want [a-zA-Z] and comma chars in a string

by davido (Archbishop)
on Oct 12, 2003 at 17:34 UTC ( #298675=note: print w/replies, xml ) Need Help??


in reply to regex: only want [a-zA-Z] and comma chars in a string

You're close.
unless ( $tax_collection =~ /^[a-zA-Z]+(?:,[a-zA-Z]+)*?$/ ) { print "<font color=\"#ff0000\"><i>Incorrect format</i></font>"; $errors++; }

What that does is it says match [a-zA-Z] as many times as possible (the first word) followed by a sequence that can be repeated as many times as necessary (or no times). That sequence may start with a comma, and finish with as many [a-zA-Z] characters as possible. The match is anchored from the front of the string to the end (assuming a single-line string).


Dave


"If I had my life to do over again, I'd be a plumber." -- Albert Einstein

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://298675]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2017-09-25 11:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (280 votes). Check out past polls.

    Notices?