Mega Code Archive

 
Categories / Perl / Regular Expression
 

The ^ and $ Pattern Anchors

^ and $ matches only at the beginning or the end of a string.  /^def/ matches def only if these are the first three characters in the string.  /def$/ matches def only if these are the last three characters in the string.  combine ^ and $ to force matching of the entire string.  /^def$/ matches only if the string is def.