This was a lightning talk given by my wife, Dana Gray, at MountainWest RubyConf 2009. She encouraged programmers to shed their fear of regular expressions and learn to use them properly.
beginning of any line - 100 lines means 100 matches \A Matches the beginning of the string - at most 1 match $ Matches the end of any line - 100 lines means 100 matches
beginning of any line - 100 lines means 100 matches \A Matches the beginning of the string - at most 1 match $ Matches the end of any line - 100 lines means 100 matches \z Matches the end of the string - at most 1 match
beginning of any line - 100 lines means 100 matches \A Matches the beginning of the string - at most 1 match $ Matches the end of any line - 100 lines means 100 matches \z Matches the end of the string - at most 1 match \Z Matches the end of the string or just before the last \n - at most 1 match
color.", "I like gray things.", "I’m hung up on a guy named Gray.", "He lives in Castle Grayskull."] /(\W|\A)gray(\W|\Z)/i /\bGray\b/i ["Gray is a great color.", "I like gray things.", "I’m hung up on a guy named Gray."]