Regular Expressions Flashcards
What module function is used to find a regex pattern to match?
A function used to find the first location of regex pattern.
How to display the matched regex pattern?
If you want to separate the regex pattern into different objects. What would you use?
Use parentheses.
A function used to print the first object of a regex pattern.
A function used to print multiple regex objects in a tuple.
This technique assigns the two values in the tuple into the two variables.
Code for finding the first instance of a phone number split it into 2 different objects
What do you need to match any of these special characters?
. ^ $ * + ? { } [ ] \ | ( )
If we want to search for the first group of a regex object. If not found move to the 2nd group, we would use what?
The pipe (|)
Code a regex object that looks for the string “Batman” as the first choice. If not found, then search for the string “Tina Fey”.
What character would you use to make a group an optional part of the search pattern?
The question mark (?)
Code a regex pattern that makes the string “wo” optional in the word “Batman”?
What character would you use to match a group ZERO or more times?
Star or asterisk (*)
Code a regex pattern that allows us to match the “wo” string inside of “Batman” zero or more times.
What character would you use to match a group ONE or more times?
Plus sign (+)
Code a regex pattern where the string “wo” inside of “Batman” has to be found at least once.
Code that specifies the group (Ha) should be matched exactly 3 times.
What character would you use to specify how many times a group should appear for it to be a match?
Brackets {}
Code that specifies the group (Ha) should be matched between 3 to 5 times.
Code that specifies the group (Ha) should be matched 3 times and beyond.
By default, Python regular expressions are greedy. What does this mean?
They match the longest string possible.