so I'm doing some playing around, trying to learn up some perl, and I have a question. what if I had two values, lets say "dog" and "dogs". If I'm looking just for "dog", how can I get it to not match "dogs". something like this.
if ( $hash{animal} =~ /^dog/ ) { if ( $hash{hair} =~ /^longhair/i ) { print "singluar longhaired dog"; } else { print "fail, you are stupid \n"; } } if ( $hash{animal} =~ /^dogs/i ) { if ( $hash{hair} =~ /^short/i ) { print "bunch of short haired dogs. \n"; } else { print "fail, you are stupid \n"; } } else { print "\nFAIL"; }
7/24/2011 1:58:43 PM
/^dog$/
7/24/2011 2:05:57 PM
/^dog[^s]/[^s] means exclude s[Edited on July 24, 2011 at 2:08 PM. Reason : .]
7/24/2011 2:08:06 PM
excellent, both worked perfectly, but I'm going to use the $ since I have a few more of these to do and don't want to get dependent on the exclude box. many thanks you 2.
7/24/2011 2:21:02 PM
/^fag(got)?[s]?$/
7/25/2011 8:24:42 AM
don't forget that /^dog$/ matches a string that is exactly 'dog'. It will not match in "I have a dog".Also, /dog[^s]/ will not match 'dogs', but it will match 'doggies'. You might want to try word boundaries instead: /\bdog\b/you might want to look in to 'look ahead' with regular expressions as well, if the library you are using supports them.a good website for reference is http://www.regular-expressions.info[Edited on July 25, 2011 at 3:50 PM. Reason : .]
7/25/2011 3:49:20 PM
ibtxkcd
7/25/2011 4:16:03 PM
/puss(y|ies)/
7/25/2011 8:41:13 PM