COMP 364: Computer Tools for Life Sciences
Regular expressions Christopher J.F. Cameron and Carlos G. Oliver
1 / 26
COMP 364: Computer Tools for Life Sciences Regular expressions - - PowerPoint PPT Presentation
COMP 364: Computer Tools for Life Sciences Regular expressions Christopher J.F. Cameron and Carlos G. Oliver 1 / 26 Key course information HW4 due tonight at 11:59:59 pm HW5 available now! due Thursday, December 7th at 11:59:59 pm
1 / 26
◮ https://horizon.mcgill.ca/pban1/twbkwbis.P_
2 / 26
◮ dynamic vs. static typing 3 / 26
◮ luv..cats@gmail.com ◮ luvmycats@gmail.com ◮ luv48cats@gmail.com 4 / 26
5 / 26
◮ conditional statements ◮ loops ◮ lists ◮ variables
6 / 26
7 / 26
8 / 26
◮ e.g., r‘[a-zA-Z]’ matches one occurrence of any ASCII
◮ similar to Python’s ‘not’ in this context 9 / 26
◮ r‘a{2}’ matches ‘aa’ in ‘naan’
10 / 26
◮ same as r‘[0123456789]’
11 / 26
12 / 26
◮ r‘[a-zA-Z]’ - matches one occurrence of an ASCII character ◮ r‘+’ - matches one or more occurrences of preceding pattern
◮ r‘-?’ - matches zero or one occurrence of ‘-’ ◮ r‘[0-9]’ - matches one occurrence of any digit
◮ r‘.’ - matches one occurrence of any character ◮ r‘zz’ - matches one occurrence of ‘zz’
◮ r‘∧’ - match start of string ◮ r‘[∧p ]’ - do not match ‘p’
◮ r‘$’ - match end of string 13 / 26
14 / 26
◮ None on failure
◮ or specific subgroup num
◮ empty if there weren’t any 15 / 26
1
2 3
4 5
6 7
8
9
10
11
12
16 / 26
1
2
3
17 / 26
18 / 26
◮ None on failure
◮ or specific subgroup num
◮ empty if there weren’t any 19 / 26
1
2 3
4 5
6 7
8
9
10
11
12
20 / 26
1
2
3
21 / 26
◮ checks for a pattern match only at the beginning of the
◮ checks for a pattern match anywhere in the string
22 / 26
1
2 3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
23 / 26
24 / 26
1
2 3
4 5
6
7
8
9 10
11
12
13
25 / 26
◮ one of the most powerful command line tools 26 / 26