Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by Anonymous Monk
on Oct 12, 2003 at 18:03 UTC ( #298681=note: print w/replies, xml ) Need Help??


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

How about just:
unless($tax_collection ~= /^([a-zA-Z]+|\b,\b)+$/) {

Replies are listed 'Best First'.
Re: Re: regex: only want [a-zA-Z] and comma chars in a string
by davido (Archbishop) on Oct 12, 2003 at 18:31 UTC
    unless($tax_collection ~= /^([a-zA-Z]+|\b,\b)+$/) {...

    No, that's not going to work because it allows the comma to appear at the beginning and/or end of the string, which doesn't meet the original post's spec. Beginning and End of string count as word boundries, so your method fails.

    Update: Now it's a matter of public record: I made a simple mistake in intrepreting Anonymous Monk's regexp. (S)He is correct in his assertion. The method works.


    Dave


    "If I had my life to do over again, I'd be a plumber." -- Albert Einstein
      Yes, Beginning and End of string count as word boundaries, but only adjacent to a \w character, which ',' is not a member of.
        Ack! You got me. haha. You are, of course, correct. \b,\b works because there is no word boundry at the junction of comma and end of string, or comma and beginning of string. It also works because there is no word boundry at the junction of two proximate commas. Good solution, and kudos for coming up with the briefest one so far. ;)


        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://298681]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2017-11-23 00:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (327 votes). Check out past polls.

    Notices?