T
Techeia
Back to Blog

Linux Regular Expressions Most Simplified

December 1, 2017
By Techeia



Regular Expressions 

.
Any single character


*
0 or more of the preceding character

+          \+
One or more of the preceding character
?          \?
0 or 1 of the preceding character
{ }         \{ \}
Match exactly num of the preceding character:
{x}-          match x repetitions
{x,}          match x or more
{,x}          match 0 – x repetitions
{x,y}        match x to y repetions


^
Match Beginning of line
$
Match End of line
<          \<
Match Beginning of word
>          \>
Match End of word


[ ]
Range – match any character within the range
[^ ]
Negation – match any character NOT within the range


( )         \( \)
Group a pattern as a single entity 
\1 ... \9
Match group \#


|           \|
Separate choices to match (| is the c-language token for logical OR)


The following have special meaning only in replacement patterns
&
Reuse the search pattern as the current replacement pattern
\u
Convert first character of replacement pattern to uppercase
\U
Convert entire replacement pattern to uppercase
\l
Convert first character of replacement patter to lowercase
\L
Convert entire replacement pattern to lowercase