Blog

python tutorials and learn python

Created with Sketch.

Python Regex Lookahead

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:…
Read more

Python Regex Non-capturing Group

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: Capturing groups Non-capturing groups So far, you learned how…
Read more

Python Regex Alternation

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…
Read more

Python Regex Backreferences

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: \N Code language: Python (python)…
Read more

Python Regex Capturing Group

Python Regex Capturing Group Summary: in this tutorial, you’ll learn about Python regex capturing groups to create subgroups for a match. Introduction to the Python regex capturing groups Suppose you have the following path that shows the news with the id 100 on a website: news/100 Code language: Python (python) The following regular expression matches…
Read more

Python Regex Sets & Ranges

Python Regex Sets & Ranges Summary: in this tutorial, you’ll learn how to use the sets and ranges to create patterns that match a set of characters. Several characters or character sets inside square brackets [] mean matching for any character or character set among them. Sets For example, [abc] means any of three characters.…
Read more

Python Regex Non-Greedy

Python Regex Non-Greedy Summary: in this tutorial, you’ll learn about the regex non-greedy (or lazy) quantifiers that match their preceding elements as few times as possible. Introduction to the regex non-greedy (or lazy) quantifiers Quantifiers allow you to match their preceding elements a number of times. Quantifiers work in one of two modes: greedy and…
Read more

Python Regex Greedy

Python Regex Greedy Summary: in this tutorial, you’ll learn about the Python regex greedy mode and how to change the mode from greedy to non-greedy. By default, all quantifiers work in a greedy mode. It means that the quantifiers will try to match their preceding elements as much as possible. Let’s start with an example…
Read more

Python Regex Quantifiers

Python Regex Quantifiers Summary: in this tutorial, you’ll learn how to use Python regex quantifiers to define how many times a character or a character set can be repeated. Introduction to Python regex quantifiers In regular expressions, quantifiers match the preceding characters or character sets a number of times. The following table shows all the…
Read more

Python Regex Word Boundary

Python Regex Word Boundary Summary: in this tutorial, you’ll learn how to construct regular expressions that match word boundary positions in a string. Introduction to the Python regex word boundary A string has the following positions that qualify as word boundaries: Before the first character in the string if the first character is a word…
Read more