Regular Expression, Regular Expression
Basic Regular Expression
First line positioning character ^
Ls | grep ^ files starting with abc
Line tail locator $
Match a single character.
. Represents any character, except for line breaks
Qualifier *
* Represents the first 0-n characters
Character Set matching []
[Abc] indicates that a character is a, B, or c.
Character Set mismatch [^]
[^ Abc] indicates a character not a, B, or c.
Expanded Regular Expression
Qualifier +
The first 1-n characters, a + indicates that there are 1 to n
Qualifier?
The first 0-1 Characters
Vertical bars | and parentheses ()
(Abc | def | ghi) indicates that the value is abc, def, or ghi.
Number of matches {m, n}
(Abc) [1, 2] indicates abc or abcabc
Perl expressions
Number match \ d
Equivalent to [0-9]
Non-digit match \ D
Equivalent to [^ 0-9]
Blank character match \ s
Equivalent to [\ f \ n \ r \ t \ v]
Non-blank character match \ s
Equivalent to [^ \ f \ n \ r \ t \ v]
Example
Start with abc and end with xyz: ^ abc. * xyz $
Not starting with abc:
Does not contain abc: