Software-Engineering
# Operators
Note: every character (space, character, number) is important when it comes to a regex-creation
Operator | Explanation |
---|
[0-9] | Finds numbers |
[a-z] / [A-Z] | Finds all lower-case/upper-case characters |
…+ | Can be found one/multiple times |
…{2} | How often a group must be repeated |
…{1, 3} | Group min.: 1 time; max.: 3 times |
? | Group 0 or exact 1 time |
. | Every character is allowed |
…|… | one OR other pattern to match |
^… | finds matchin item at the beginning |
$… | finds last matching item |
[^ ] | negation - finds everything, that does not match the pattern |
\d | == [0-9] |
\D | == [^ 0-9] |
\s | any whitespace character |
\S | any non-whitespace character |
\w | == [a-zA-Z0-9] |
\W | == [^ a-zA-Z0-9] |
# Methods
# pattern.findall()
Returns a list of matching items. For simple use-cases (returns no position).
# pattern.search()
This method returns an Match-object
, if nothing is found - it returns None
.
A Match-object
provides lots of methods & attributes.
# pattern.finditer()
It returns Match-objects
. Allows analysing of matching patterns (incl. positions in text).
# pattern.match()
It checks if the pattern at the beginning of the text matches a certain condition.
# Examples
# .findall()
# .search()