O'Reilly logo

A Practical Guide to Red Hat® Linux® 8 by Mark G. Sobell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Rules

The following rules govern the application of regular expressions.

Longest Match Possible

As stated previously, a regular expression always matches the longest possible string, starting as far toward the beginning of the line as possible. For example, given the following 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 following 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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required