Definition and Purpose of Regex
■ Regular expressions or regex is a specialized language and essential administrator tool used to describe and match patterns within text
■ Regex is not a command ■ Regex is a series of character-based structures that define patterns used for searching text ■ Regex allows rapid location of specific patterns in large amounts of text ■ Regex is useful for troubleshooting and incident response ■ Regex is used to filter command output and automate text processing tasks
Wildcard character
. matches any single character
. example
c.t matches cat cot or c-t
\ character
treats the next character as a literal
\ character example
cowa.bunga matches only cowa.bunga not cowaabunga or cowa-bunga
^ anchor
anchors pattern to beginning of line
^ example
^Hello matches lines beginning with Hello
$ anchor
anchors pattern to end of line
$ example
world$ matches lines ending with world
[a-z]
matches any single lowercase letter a to z
[0-9]
matches any single digit
[a-z] example
ox matches fox box and pox
?
matches zero or one occurrence of the preceding element
*
matches zero or more occurrences of the preceding element
+
matches one or more occurrences of the preceding element
{n}
matches exactly n occurrences of the preceding element