Regular Expressions


Searching for text within files requires the use of regular expressions. Regular expressions can be either common regular expressions or extended regular expressions. An introduction to both types of expressions can be seen in Tables A.7 and A.8.

Not all utilities recognize both types of regular expressions, so be sure you are using the correct form for whatever utility you are using.

Table A.7. Common Regular Expressions

COMMAND

EXAMPLE

DESCRIPTION

.

test. matches test1, test2, test3

Matches any single character.

*

test* matches test, testt, testtt

Matches zero or more occurrences of the preceding character.

^

^test matches any line containing test as the first word

Matches the following characters if they are found at the beginning of a line.

$

test$ matches any line containing test as the final word

Matches the preceding characters if they are found at the end of a line.

\

test\$ matches test$

Used to escape metacharacters used in other regular expressions.

[...]

test[1234] matches test1, test2, test3, and test4 test[1-4] also produces the same results

Matches one character in the specified range of possible characters.

[^...]

test[^1234] matches test5, test6, test7, and so on. test[^1-4] also produces the same results

Matches one character not found in the specified range of characters.


Table A.8. Extended Regular Expressions

COMMAND

EXAMPLE

DESCRIPTION

?

test? matches tes, test

Matches zero or one occurrences of the previous character.

+

test+ matches test, testt, testtt

Matches one or more occurrences of the previous character.

{ }

test{ 2} matches testt test{ 1,4} matches test, testt, testtt, testttt

Matches the specified number of occurrences of the previous character. Two numbers separated by a comma are used to specify a range of numbers.

(...|...)

(From|Subject) matches the word From or Subject. Th(ey|eir) matches the word They or Their.

Matches either of two sets of characters.




    NovellR Open Enterprise Server Administrator's Handbook SUSE LINUX Edition
    Novell Open Enterprise Server Administrators Handbook, SUSE LINUX Edition
    ISBN: 067232749X
    EAN: 2147483647
    Year: 2005
    Pages: 178

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