Tutorial 3
Tutorial 3
● Overview of exercise 2
● Recap of concepts introduced
in the lecture
● Ultimate regex/unix
commands/grep recap
Tips and Remarks:
Exercise 2
Task 1: get to know the Python interpreter, no
hand in
● Important: check the python - Let's the interpreter know what encoding
version you’re using! is being used
Text Editors for Python-Files
● Python programs are basically simple text files with
a .py extension.
We'll give you
a short
● Use the text editors introduced in the first introduction to
VSCode!
tutorial
mark groups
This groups multiple characters together. Useful for applying quantifiers to multiple characters or capturing
(...) substrings.
If you search with the regex: '(ca)+', it matches: ca, caca, cacaca, etc.
backreference to groups
\1 To find repeated words:
If you search with the regex: '(\w+)\s+\1', it matches: 'hello hello', 'bye bye', etc.
match at beginning (if at beginning of regex), negation (if not, e.g. [^x])
If at the beginning of regex, it matches the start of a line. If used within [], it negates.
^ Example:
- Start of Line Regex: ^ca, it matches: ca in cat but not in space
- Negation Regex: [^x], it matches: any single character except x.
regexone.com
characters. characters.
'\s' matches the space in matches c in "cat sat". matches a in "cat_9". matches ! in "cat!".
"cat sat".
{n}
+ * ?
Matches the preceding
Matches 1 or more of the Matches 0 or more of the preceding Matches 0 or 1 of the
character or group exactly
preceding element. element. preceding element.
n times.
'ca+t' matches cat, caat, 'ca*t' matches ct, cat, caat, etc. 'ca?t' matches ct and 'ca{2}t' matches: caat but
etc. cat, but not caat. not cat or caaat.
Additional Regex Practice
regexone.com
unix commands recap
wc Count lines, words, characters
Show current directory
pwd Useful to if you need to know which file path
you're in
ls –l See files in directory
more file.txt Look into the file
-h Hide filenames
-c count