Perl Regex
Perl Regex
Perl Regex
H
a
z
a
r
d
o
u
s
t
o
y
o
u
r
h
e
a
l
t
h
/(?:group)/
Cert ain charact ers are overloaded; recall:
count t he number of * in $_
$cnt = tr/*/*/
$cnt = $_ =~ tr/*/*/
change all non-alphabet ic charact ers t o
spaces
tr/a-zA-Z/ /c
not ice space + c = complement search st ring
delet e all non-alphabet ic charact ers complet ely
tr/a-zA-Z//cd
d = delet e found but unreplaced charact ers
Universit y of Vict oria
Depart ment of Comput er
Science
SENG 265: Sof t ware Development
Met hods
Perl Regular Expression: Slide 35
Using t he result s of mat ches
wit hin a pat t ern
\1, \2, \3 refer t o what a previous set of
parent heses mat ched
abc abc =~ /(\w+) \1/ # matches
abc def =~ /(\w+) \2/ # doesnt match