#delimiter for Metacharacters ^ $ ( ) \ | @ [ { ? . + * $_ = "c:/mywork/hangman"; if (m/c:\/mywork\/hangman/) { print "Found the hangman game!\n\n" } # + causes the preceding character to match at least once $content = "hotdog"; if ($content =~ m/do+g/) { print "found do+g : $content\n\n"; } $content = "hotdooooooooooooog"; if ($content =~ m/do+g/) { print "found do+g : $content\n"; print "pattern that match: $&\n\n"; #$& stores pattern matched } #* metacharacter is similar to the + metacharacter, but it causes the preceding character to be matched zero or more times. $content = "hotdg"; if ($content =~ m/do*g/) { print "found do*g : $content\n\n"; } $content = "hotdoooooooooooooog"; if ($content =~ m/do*g/) { print "found do*g : $content\n\n"; } #exact match, {n,m} n is the minimum number of matches, m is the maximum number of matches $content = "xxxwing"; if ($content =~ m/x{2,4}/) { print "found x{2,4} : $content\n\n"; } else { print "not found x{2,4} : $content\n\n"; } #[] "any of these characters." $content = "xxxwing"; if ($content =~ m/[a-e]{2,4}/) { print "found [a-e]{2,4} : $content\n\n"; } else { print "not found [a-e]{2,4} : $content\n\n"; } $content = "xxxwing"; if ($content =~ m/[x-z]{2,4}/) { print "found [x-z]{2,4} : $content\n\n"; } else { print "not found [x-z]{2,4} : $content\n\n"; } #if a caret (^) occurs as the first character of a character class, the character class is negated. #[^A-Z] Matches non-uppercase-alphabetic characters. $content = "xxxwing"; if ($content =~ m/[^A-Z]{2,4}/) { print "found [^A-Z]{2,4} : $content\n\n"; } else { print "not found [^A-Z]{2,4} : $content\n\n"; } #\w A word character; same as [a-zA-Z0-9_] $content = "x1X2x3wing"; if ($content =~ m/\w{2,10}/) { print "found \w{2,10} : $content\n\n"; } else { print "not found \w{2,10} : $content\n\n"; }