in reply to Regular Expression Question
It would probably be far easier to first verify that the string contains legitimate characters and then check whether or not any of the conditions that would make it illegal exist.
#!/usr/bin/perl -wl use strict; for (<DATA>) { chomp; if (! /[^a-zA-Z0-9,]/ and ! /^,|,{2}|,$/) { print "Yep: $_"; } else { print "Nope: $_"; } } __DATA__ this,should,work,11 ,this,should,not,work this,,too,should,not,work nor,this,one,
Please please please read perldoc perlretut and perldoc perlre for a deeper understanding of regular expressions.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Regular Expression Question
by TASdvlper (Monk) on Dec 04, 2003 at 20:12 UTC | |
by nevyn (Monk) on Dec 04, 2003 at 20:25 UTC |