Section A.2. Extended Regular Expressions


[Page 597]

A.2. Extended Regular Expressions

Some utilities such as egrep support an extended set of metacharacters, which are described in Figure A-3.

Figure A-3. Extended regular expression metacharacters.

Metacharacter

Meaning

+

Matches one or more occurrences of the single preceding character.

?

Matches zero or one occurrence of the single preceding character.

| (pipe symbol)

If you place a pipe symbol between two regular expressions, a string that matches either expression will be accepted. In other words, a | acts like an "or" operator.

()

If you place a regular expression in parentheses, you may use the *, +, or ? metacharacters to operate on the entire expression, rather than just a single character.


Figure A-4 lists some examples of full regular expressions, using the example file from Section A.1.1.

Figure A-4. Lines matching extended regular expression patterns.

Pattern

Lines that match

s.*w

Oh you sleepy young heads dream of wonderful things,

Beautiful mermaids will swim through the sea,

And you will be swimming there too.

s.+w

Oh you sleepy young heads dream of wonderful things,

Beautiful mermaids will swim through the sea,

off|will

So turn off the light,

Beautiful mermaids will swim through the sea,

And you will be swimming there too.

im*ing

And you will be swimming there too.

im?ing

<no matches>





Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net