From: Glenn Jackman Date: 2009-07-15T03:40:07+09:00 Subject: Re: a regex that does not contain comma At 2009-07-14 08:54AM, "David A. Black" wrote: > Hi -- > > On Tue, 14 Jul 2009, Glenn Jackman wrote: > > > case string > > when /,/ then puts "#{string.inspect} contains a comma" > > when /^[^,]*$/ then puts "#{string.inspect} has no comma" > > end > > That second regex, on its own, won't tell you the whole story: > > string = <<-EOM > Hi. > I have, at a minimum, two commas. > Bye. > EOM > > p "Match!" if /^[^,]*$/.match(string) > => Match! > > You'd want to use \A and \z, rather than ^ and $ (which delimit lines, > rather than the whole string). > > But if you've already tested for /,/, then you should be able just to > have an else clause in your case statement, to cover cases where /,/ > didn't match. Yes, I could have used the else clause, but I wanted to explicitly spell out the "negation" of /,/ in case the OP required it. Coming from Tcl and Perl, and being used to line-wise parsing, I wasn't fully aware of the difference between ^$ and \A\Z Thanks for learnin' me. -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous