Mega Code Archive

 
Categories / Perl / Regular Expression
 

Some Regular Expression Metacharacters

Metacharacter   Represents ^               Matches at the beginning of a line $               Matches at the end of a line a.c             Matches an 'a', any single character, and a 'c' [abc]           Matches an 'a' or 'b' or 'c' [^abc]          Matches a character that is not an 'a' or 'b' or 'c' [0-9]           Matches one digit between '0' and '9' ab*c            Matches an 'a', followed by zero or more 'b's and a 'c' ab+c            Matches an 'a', followed by one or more 'b's and a 'c' ab?c            Matches an 'a', followed by zero or one 'b' and a 'c' (ab)+c          Matches one or more occurrences of 'ab' followed by a 'c' (ab)(c)         Captures 'ab' and assigns it to $1, captures 'c' and assigns it to $2.