An Introduction to Regular Expressions The Basics 8 of 50 : [PREV] [NEXT]

Standard Meta Characters

Some characters don't match themselves, but are metacharacters. You can match these characters literally by placing a backslash in front of them. For example, "\\" matches a backslash and "\$" matches a dollar-sign. Here's the list of metacharacters:

\ | () [ { ^ $ * + ? .

A backslash also turns an alphanumeric character into a metacharacter. So whenever you see a backslash followed by an alphanumeric character:

\d \D \w \W \t \s \3

you'll know that the sequence matches something strange. For example, \t matches a tab character, while \d matches any digit. Some sequences are actually zero characters wide. For instance, "\b" matches a word boundary, which is not a real character -- it is zero characters wide.

Regular expression are mostly assertions, i.e. plain characters that simply assert that they match themselves. We'll use the term "assertions" for the zero-width ones. Non-zero-width assertions are called atoms. As there is no standard terminology, we use the one from "Programming Perl."


© 2003 Barbie barbie@missbarbell.co.uk Home http://birmingham.pm.org/