Regular Expression (Python) Flashcards
Importing the regular expression module
import re
Use a function to search for ‘blue’ ins string ‘Rythm and blues’
re.search(r”blue”, “Rhythm and blues”)
Regex to match the following in order:
A single open bracket character.
One or more word characters.
A single close bracket character.
[/w+]
Any character except f , F, d, 3, or whitespace
[^fFud\s]
Non-digit characters
\D
--OR--
[^0-9]
Any three characters except newline then followed by a period
.{3}.
Find ‘th’ only when not at the start or end of a word
\Bth\B
find ‘abc’ only when at the start or end of a string
^abc|abc$
Regex to match the following in order:
Capture group of one non-word character then digit
Non-whitespace then ‘'
The capture group repeated 2 to 4 times
(\W\d)\s\\1{2,4}
Create a non-capture group containing ‘kevin’ or ‘candace’
(?:kevin|candace)
Any letter repeated at least twice
([a-zA-Z])\1{1,}
Matches ‘zzz’ only when it is followed by ‘abc’
zzz(?=abc)
Matches ‘zzz’ only when it is not followed by ‘abc’
zzz(?!abc)
Matches ‘zzz’ only when it is preceded by ‘abc’
(?<=abc)zzz
Matches ‘zzz’ only when it is not preceded by ‘abc’
(?