Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by jeroenes (Priest)
on Oct 12, 2003 at 17:36 UTC ( #298676=note: print w/ replies, xml ) Need Help??


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

Hi heezey,

Why not try without regex?

print "yes" if not tr/a-zA-Z,//c and not ( str( $_, ',', 0) or str $_, + ',' ,-1);
Did not check it but should work.

Cheers,

Jeroen "We are not alone"(FZ)

After some self-flaggalation:

for (qw/ ,asd asd:asd asd, asd,asd asd,,asd/){ my $test = $_; print "$test: "; print "yes" unless $test=~tr/a-zA-Z,//c or index( $test, ',') == 0 or + index( $test, ',') == -1 + length( $test) or index( $test, ',,') > 0 +; print "\n"; }

My perl clearly is rusty, and I even don't know anymore in which language str is valid ;).

However, still possible without regexes {grin}.


Comment on Re: regex: only want [a-zA-Z] and comma chars in a string
Select or Download Code
Replies are listed 'Best First'.
Re: Re: regex: only want [a-zA-Z] and comma chars in a string
by Anonymous Monk on Oct 12, 2003 at 17:42 UTC
    bzzt! Why post guesses when 10 seconds would have allowed you to check? The strings are not allowed to have consecutive commas, and str($_,',',0) isn't even a valid Perl function.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (15)
As of 2015-07-07 20:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls