/abc/ is an RE that matches "abc"
a-z A-Z 0-9 () = ; : ,
* . [] ? + / \ -
/" here.
Regular expressions are used by many Unix utilities:
sed (Unix stream editor)
ex (Unix line editor)
vi (Unix visual editor)
emacs (general-purpose editor)
grep (file searching tool)
awk (pattern scanning and processing language)
perl (scripting language)
% grep "abc" filename
Prints out all lines in the given file containing
"abc" somewhere in them
% grep -i "abc" filename
Same as above, but ignores case of the desired
string
% grep -v "abc" filenamePrints out all lines in the given file that do not contain "
abc" anywhere in them.
.
/a.c/ matches: abc adc aec a=c a:c
/x..x/ matches: xaax xavx x=kx
*
/ab*c/ matches: ac abc abbc abbbbbbbbbbbbbbbbc
/a*/ matches: "" a aa aaaaaaaaaa
/a*b*c*/ matches: ?
/.*/ matches: ?
[]
* and $ lose their special meaning
^ at the start means NOT
- between characters refers to a range
/[Mm]ark/ matches: mark Mark
/t[aeiou]x/ matches: tax tex tix tox tux
/[abc].*/ matches: anthing beginning with a or b or c
/[a-z][a-z]/ matches: any two-letter lower-case string
/[a-zA-Z]*/ matches: any word made of letters
/[^abc].*/ matches: anything starting with something
besides a or b or c
/[a-zA-Z0-9_]*/ matches: ?
^
/^T/ matches: all lines starting with T
/^[0-9]/ matches: ?
$
/T$/ matches: all lines ending with T
/^$/ matches: ?
\
/\./ matches: .
/a\*b/ matches: a*b
This (rug) is not what it once was (a long time ago), is it?
/Th.*is/ matches: ?
/(.*)/ matches: ?
+
*, but matches one or more occurrences of
the preceding RE
/ab+c/ matches: abc abbc abbbc
but not ac
?
/ab?c/ matches: ac abc
|
/abc|def/ matches: abc def
( )
\( and \)
instead
/ab(c|d)ef/ matches: abcef abdef