Rules

 < Day Day Up > 

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/ ).

     < 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