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 UNIX[r] for Mac OS[r] X Users
A Practical Guide to UNIX for Mac OS X Users
ISBN: 0131863339
EAN: 2147483647
Year: 2005
Pages: 234

Similar book on Amazon

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