Regular Expressions that I have been taught.
Regular expression is a tool for matching patterns in text. With the help of regular expression you can find, match and replace text in strings.
A regular expression is a special sequence of characters that helps you match or find other strings or sets of strings, using a specialized syntax held in a pattern.
Module name re is imported to be used.
White Space Characters
Any single character or number
Anything but a number (non-digit character)
Anything but a space
Any character (A-Z, a-z, 0-9 and underscore)
Anything but a character
Any single character except for a new line
The white space around words
Syntax - re.match(pattern, string, <flag=0>)
For any pattern in the string - only the first match
Matches all occurrences
Splits the string - forms an array
To replace one or more characters in a string
We expect x to y integers
Match one or more occurrences
Match 0 or 1 occurrence
Match 0 or more of the preceding expression (eg. x* will match occurrences of x)
Match the end of the string
Matching the beginning of a string
Used as OR
Displaying a range
To group the regular expressions
Help Us Go Positive!
We offset our carbon usage with Ecologi. Click the link below to help us!