Rules


The following rules govern the application of regular expressions.

Longest Match Possible

A regular expression always matches the longest possible string, starting as far toward the beginning of the line as possible. For example, given the string

This (rug) is not what it once was (a long time ago), is it?


the expression /Th.*is/ matches

This (rug) is not what it once was (a long time ago), is


and /(.*)/ matches

(rug) is not what it once was (a long time ago)


However, /([^)]*)/ matches

(rug)


Given the string

singing songs, singing more and more


the expression /s.*ing/ matches

singing songs, singing


and /s.*ing song/ matches

singing song


Empty Regular Expressions

Within some utilities, such as vim and less (but not grep), an empty regular expression represents the last regular expression that you used. For example, suppose you give vim the following Substitute command:

:s/mike/robert/


If you then want to make the same substitution again, you can use the following command:

:s//robert/


Alternatively, you can use the following commands to search for the string mike and then make the substitution

/mike/ :s//robert/


The empty regular expression (//) represents the last regular expression you used (/mike/).




A Practical Guide to Red Hat Linux
A Practical Guide to Red HatВ® LinuxВ®: Fedoraв„ў Core and Red Hat Enterprise Linux (3rd Edition)
ISBN: 0132280272
EAN: 2147483647
Year: 2006
Pages: 383

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