User:Tsu2/Regular Expressions

Jump to: navigation, search

Regular Expressions

What is a Regular Expression?

Regular Expressions are strings with one or more characters of special significance.
Unless escaped, the special character will signify some special operation and often is used for some kind of expansion. A common example is the wildcard (*) which allows unspecified characters to be substituted and appended or prepended to the specified string.

Regular Expressions

This is an important concept particularly for anyone who also uses a MSWindows console. In the Windows world, the entire Regular Expression is passed to the command, but in the Unix world Regular Expressions behave differently. Instead, the shell operates on the Regular Expression first and separately before then passing the result to the command, which can produce a different result than in Windows. The following describes behavior in BASH, but different shells may behave differently.

Quoting Regular Expressions

Currently, zypper does not automatically quote input.
One of the consequences of this is that a Regular Expression can be expanded in unexpected and undesirable ways.

So, for instance the following wildcard (*) both unquoted and quoted... If you wanted to search for all installed packages with "Network" in the package name with the following

zypper se -i Network*

The above will actually search using the string "Networking" instead of "Network" as intended, which can be revealed by

echo Network*

The solution to avoiding this unintended Pathname Expansion is to quote the Regular Expression which will then return all installed package names with the string "Network" in the name

zypper se -i 'Network*'

For the above, double quotes or single quotes are sufficient, but for some other types of Regular Expressions a double quote will allow certain types of expansion.

For more reading about Regular Expressions and expansion

The steps BASH processes input
http://mywiki.wooledge.org/BashParser

"Learning the Shell" - Expansion
http://linuxcommand.org/lc3_lts0080.php