Regular expressions are the key to powerful, exible, and efŒcient text processing. Regular expressions themselves, with a general pattern notation almost like a mini programming language, allow you to describe and parse text. When scratch some web information from Internet, I realize the power of Regular Expressions. From today, I will study the RE step by step.
Some definations or speacial terms should be given first!
Metacharacters: Full regular expressions are composed of two types of characters. The special characters (like the "+" "." ) are called metacharacters,while
the rest are called literal, or nor mal text characters
What sets regular expressions part from Œlename patterns are the advanced expressive powers that their metacharacters provide. Filename patterns provide limited metacharacters for limited needs, but a regular expression ™languageš provides rich and expressive metacharacters for advanced uses.
Egrep:Finding text is one of the simplest uses of regular expressionsŠmany text editors and word processors allow you to search a document using a regular-expr ession pattern. Even simpler is the utility egrep.
Figure 1 shows you some metachracters that I have learnt from the book "Mastering Regular Expressions"
(1) The metacharacter "." (usually called dot or point) is a shorthand for a character class that matches any character.
Example:
if you want to search for a date such as 03/19/76, 03-19-76, or even 03.19.76, you could go to the trouble to construct a regular expression that uses character classes to
explicitly allow `/', `-', or `.' between each number, such as 03[-./]19[-./]76.
However, you might also try simply using 03.19.76
(2) The regular-expression construct "[ ]", usually called a character class.
Example:
"[123456]" matches any of the listed digits.
(3) "[^]" instead of "[]", the class matches any character that isn't listed.
Example:
"[^1-6]" matches a character that's not 1 thr ough 6.
Continue:::::