Appendix Summary

 < Day Day Up > 

A regular expression defines a set of one or more strings of characters. A regular expression is said to match any string it defines.

In a regular expression, a special character is one that does not represent itself. Table A-9 lists special characters.

Table A-9. Special characters

Character

Meaning

.

Matches any single character

*

Matches zero or more occurrences of a match of the preceding character

^

Forces a match to the beginning of a line

$

A match to the end of a line

\

Used to quote special characters

\ <

Forces a match to the beginning of a word

\ >

Forces a match to the end of a word


Table A-10 lists ways of representing character classes and bracketed regular expressions.

Table A-10. Character classes and bracketed regular expressions

Class

Defines

[xyz ]

Defines a character class that matches x, y, or z

[^ xyz ]

Defines a character class that matches any character except x, y, or z

[x z ]

Defines a character class that matches any character x through z inclusive

\ ( xyz \ )

Matches what xyz matches (a bracketed regular expression)


In addition to the preceding special characters and strings (excluding quoted parentheses, except in vim), the characters given in Table A-11 are special within full, or extended, regular expressions.

Table A-11. Extended regular expressions

Expression

Matches

+

Matches one or more occurrences of the preceding character

?

Matches zero or one occurrence of the preceding character

(xyz )+

One or more occurrences of what xyz matches

(xyz )?

Zero or one occurrence of what xyz matches

(xyz )*

Zero or more occurrences of what xyz matches

xyz |abc

Either what xyz or what abc matches (use \| in )

(xy |ab)c

Either what xyc or what abc matches (use \| in vim)


Table A-12 lists characters that are special within a replacement string in sed and vim.

Table A-12. Replacement strings

String

Represents

&

Represents what the regular expression (search string) matched

\n

A quoted number, n, represents what the nth bracketed regular expression in the search string matched


     < Day Day Up > 


    A Practical Guide to LinuxR Commands, Editors, and Shell Programming
    A Practical Guide to LinuxR Commands, Editors, and Shell Programming
    ISBN: 131478230
    EAN: N/A
    Year: 2005
    Pages: 213

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