Regular Expressions

Regular Expressions

Regular Expressions


Regular expression is a notation for patterns of text, as opposed to exact strings of characters. The notation uses literal characters and metacharacters. Every character which does not have special meaning in the regular-expression syntax is a literal character and matches an occurrence of that character. For example, letters and numbers are literal characters. A metacharacter is a symbol with special meaning (an operator or delimiter) in the regular-expression syntax.

.

Wildcard: any character

*

Repeat: zero or more occurrences of previous character or class

^

Line position: beginning of line

$

Line position: end of line

[class]

Character class: any character in the set

[^class]

Inverse class: any character not in the set

[x-y]

Range: any characters within the specified range

\x

Escape: literal use of metacharacter x

\<xyz

Word position: beginning of the word

xyz\>

Word position: end of the word

For example, the following regular expression .* matches any string of characters, ^a matches any string beginning with character a.