A Python regular expression is a sequence of metacharacters that define a search pattern used to find or find and replace strings. Common regex functions include search(), findall(), split(), sub(), and functions of match objects like start(), span(), and string(). Regular expressions can match characters, quantifiers, word boundaries, and more.
1. Regular Expressions
A Python regular expression is a sequence of metacharacters that define
a search pattern. We use these patterns in a string-searching algorithm
to "find" or "find and replace" on strings
The match Function
This function attempts to match RE pattern to string with optional flags.
Here is the syntax for this function −
2. Search, findall()
• The re.search() method takes a regular expression pattern and a
string and searches for that pattern within the string. If the search is
successful, search() returns a match object or None otherwise
• findall() is probably the single most powerful function in the re
module. Above we used re.search() to find the first match for a
pattern. findall() finds *all* the matches and returns them as a list of
strings, with each string representing one match.
6. • []-Returns a match if string contains pattern
• ^- starts eith given pattern
• $-ends
• .-any char except new line
• *-zero or more occurances
• +-one or more occurances
• {}-specifies no.of occurances
• /-special occurances