Download presentation
Presentation is loading. Please wait.
Published byTyrone Richards Modified over 8 years ago
1
LING/C SC/PSYC 438/538 Online Lecture 7 Sandiway Fong
2
Homework Read textbook chapter 2, section 1 – Regular Expressions
3
Homework – Read up on the syntax of Perl Regular Expressions – Online tutorials http://perldoc.perl.org/perlrequick.html http://perldoc.perl.org/perlretut.html
4
Perl Regular Expressions Perl regular expression (re) matching: – $a =~ /foo/ – /…/ contains a regular expression – will evaluate to true/false depending on what’s contained in $a Perl regular expression (re) match and substitute: – $a =~ s/foo/bar/ – s/…match… /…substitute… / contains two expressions – will modify $a by looking for a single occurrence of match and replacing that with substitute – s/…match… /…substitute… /g global match and substitute
5
Perl Regular Expressions Most useful with the code template for reading in a file line- by-line: open($txtfile,$ARGV[0]) or die "$ARGV[0] not found!\n"; while ($line = ) { do RE stuff with $line }
6
Perl Regular Expressions character class: Perl lingo
7
Perl Regular Expressions backslash lowercase letter for class Uppercase variant for all but class backslash lowercase letter for class Uppercase variant for all but class
8
Chapter 2: JM
9
Sheeptalk
10
Chapter 2: JM
11
Perl Regular Expressions Precedence of operators – Example: Column 1 Column 2 Column 3 … – /Column [0-9]+ */ – /(Column [0-9]+ *)*/ – /house(cat(s|)|)/ Perl: – in a regular expression the pattern matched by within the pair of parentheses is stored in designated variables $1 (and $2 and so on) Precedence Hierarchy: space
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.