Author: admin
-
Python Regex search()
Summary: in this tutorial, you’ll learn how to use the Python regex search() function to return the first match of a pattern in a string. Introduction to the Python regex search() function The regex search() is a function in the built-in re module that deals with regular expressions. The search() function has the following syntax: In this syntax: The search() function scans the string from left to right…
-
Python Regex match()
Summary: in this tutorial, you’ll learn how to use the Python regex match() function to find a match with a pattern at the beginning of a string. Introduction to the Python regex match function The re module has the match() function that allows you to search for a pattern at the beginning of the string: In this syntax: If the search is successful, the match() function…
-
Python Regex finditer()
Summary: in this tutorial, you’ll learn how to use the Python regex finditer() function to find all matches in a string and return an iterator that yields match objects. Introduction to the Python regex finditer function The finditer() function matches a pattern in a string and returns an iterator that yields the Match objects of all non-overlapping matches. The following shows the syntax…
-
Python Regex fullmatch()
Summary: in this tutorial, you’ll learn how to use the Python regex fullmatch() to match the whole string with a regular expression. Introduction to the Python regex fullmatch function The fullmatch() function returns a Match object if the whole string matches the search pattern of a regular expression, or None otherwise. The syntax of the fullmatch() function is as follows: In this syntax: Python regex fullmatch…
-
Python Regex findall()
Summary: in this tutorial, you’ll learn how to use the Python regex findall() function to find all matches of a pattern in a string. Introduction to the Python regex findall() function The findall() is a built-in function in the re module that handles regular expressions. The findall() function has the following syntax: In this syntax: The findall() function scans the string from left to right and finds all the matches…
-
Python Regex Lookbehind
Summary: in this tutorial, you’ll learn about Python regex lookbehind and negative lookbehind. Introduction to the Python regex lookbehind In regular expressions, the lookbehind matches an element if there is another specific element before it. The lookbehind has the following syntax:(?<=Y)X In this syntax, the pattern will match X if there is Y before it. For example, suppose you have…
-
Python Regex Lookahead
Summary: in this tutorial, you’ll learn about Python regex lookahead and negative lookahead. Introduction to the Python regex lookahead Sometimes, you want to match X but only if it is followed by Y. In this case, you can use the lookahead in regular expressions. The syntax of the lookahead is as follows: This syntax means to search for X but matches…
-
Python Regex Non-capturing Group
Summary: in this tutorial, you’ll learn about the Python regex non-capturing group to create a group but don’t want to store it in the groups of the match. Introduction to the Python regex non-capturing group Regular expressions have two types of groups: So far, you learned how to use a capturing group to extract information from a…
-
Python Regex Alternation
Summary: in this tutorial, you’ll learn about Python regex alternation, which behaves like the “OR” operator in regular expressions. Introduction to the Python regex alternation To represent an alternation in regular expressions, you use the pipe operator (|). The pipe operator is called the alternation. It is like the or operator in Python. The following regular expression uses an…
-
Python Regex Backreferences
Summary: in this tutorial, you’ll learn about Python regex backreferences and how to apply them effectively. Introduction to the Python regex backreferences Backreferences like variables in Python. The backreferences allow you to reference capturing groups within a regular expression. The following shows the syntax of a backreference: Alternatively, you can use the following syntax: In this syntax, N can be 1, 2,…