Introduction to Regular Expression for sed & awk by Susan Lukose Regular Expression • Regular Expression way to match text with patterns Regular Expression Example of Matched Text Example.

Download Report

Transcript Introduction to Regular Expression for sed & awk by Susan Lukose Regular Expression • Regular Expression way to match text with patterns Regular Expression Example of Matched Text Example.

Introduction to Regular
Expression for sed & awk
by
Susan Lukose
Regular Expression
•
Regular Expression way to match text with patterns
Regular Expression
Example of
Matched Text
Example of
Unmatched Text
abc
abcdefg
cccdabcgf
bcagjjfg
gjkgfkk
^abc
abcjjdje
dgabcjjjd
abc$
jhsjdabc
abc
abcchghhsd
a.b
acb
davb
avhsjvhb
ab
a.*b
ab
ajjdjkxb
ba
a*b
bhsghgh
aaaaaabmnjkk
acb
a.+b
acb
ahjhhjjbcsdfs
ab
a+b
aaaaaab
bkfjdkj
Regular Expression
regular expression
a?b
•
example of matched text
bc
abd
{n} Match exactly n times
{n,} Match at least n times
{n,m} Match at least n but not more than m times
example of unmatched text
aab
Regular Expression
•
Grouping could be done with ()
–
–
•
Class could be specified []
–
–
–
•
•
(ab)
gg(ab)*gg
[abc] Match any of a, b, and c.
[a-z] Match any character between a and z. (ASCII order)
[^abc] A caret ^ at the beginning indicates "not". In this case, match anything other than a, b, or c.
regular expression should be specified between //
Special characters like ^, $, . etc.. Could be matched by escaping with \