🌐
Medium
medium.com › @tubelwj › commonly-used-python-regular-expression-examples-065526b5b8b5
Commonly Used Python Regular Expression Examples | by Gen. Devin DL. | Medium
January 2, 2025 - In this post we will demonstrate how to use regular expressions in Python to solve some common problems through examples.
🌐
GeeksforGeeks
geeksforgeeks.org › python › regular-expression-python-examples
Python RegEx - GeeksforGeeks
August 14, 2025 - You can use RegEx in Python after importing re module. ... This Python code uses regular expressions to search for the word "portal" in the given string and then prints the start and end indices of the matched word within the string.
Discussions

Probably the best tutorial on regular expressions I have ever read

Is that like "my best root canal ever"?

More on reddit.com
🌐 r/Python
53
376
December 4, 2013
Which is the best place to learn and practice regular expressions in Python?
You could use https://regex101.com for practice, it has the Python flavor of regexes, and of course you can use any text and regex to see how they interact. It even explains each regular expression to its component parts. And it can provide you with ready-made code. More on reddit.com
🌐 r/learnpython
60
143
September 3, 2018
Explain Like I'm 5: Regular Expressions
IMHO making eyes glaze over is what regular expressions excels at. I hate it with a passion. That being said, it is a powerful, useful tool for parsing text. The key thing that triggered my understanding of regex is that all characters/arguments/etc are positional. They aren't flags, triggers, or what have you, they match the literal of what they represent at that position in your regex string. So, a quick example. I use this in a script of mine for grabbing a version string. "^[0-9]+\.[0-9]+\.[0-9]+" It literally matches start of line, one or more of the digits of zero through nine, a period, one or more digits of zero through nine, a period, one or more digits of zero through nine The carat ^ matches the literal start of line. [0-9] is a kind of specified wildcard, it says the character here can match any digit zero through nine. + is a special character that extends the previous argument in the string ([0-9]) and says to match it at least once and then for as many times as it positively matches. \ is the escape character, it says 'treat the following argument as a string literal, not as a special character'. . since it was escaped by \, we are looking for a literal period/decimal-point. From there, the sequence repeats. It will match any of these, and more: 1.0.5, 15.154.42, 0.0.5 I'm not on my computer with my scripts so I don't have the actual function it's used in handy. I really struggled hard to wrap my head around regular expressions, and I really hope this helps. If you want, I'll come back later when I have access to my scripts and post some actual in-use functions. More on reddit.com
🌐 r/learnpython
43
65
July 3, 2014
What did you use to learn Regular Expressions?

I've used a few different sites to help me get my mind around regex.

This is good for experimenting with different regular expressions online: http://www.regexr.com/

This helped me learn some basic regex principles: http://www.regular-expressions.info/tutorial.html

I'm not even close to awesome at RegEx; google is usually my friend. But, as with anything, the best way to learn is with practice.

More on reddit.com
🌐 r/learnjavascript
14
15
April 5, 2013
🌐
Mimo
mimo.org › glossary › python › regex-regular-expressions
Python Regex: Master Regular Expressions in Python
In this example, re.search() checks if the word "learn" exists in the text and returns the first match. Regex is commonly used in Python 3 for working with unicode strings. In many server applications, logs are generated in structured text formats. Regular expressions extract useful data, such as error codes, timestamps, and user activity.
🌐
Mooc
programming-25.mooc.fi › part-12 › 4-regular-expressions
Regular expressions - Python Programming MOOC 2025
This second example looks for any numbers in a string. The findall function returns a list of all the instances which match the pattern: import re sentence = "First, 2 !#third 44 five 678xyz962" numbers = re.findall("\d+", sentence) for number in numbers: print(number) ... Let's get familiar with the basic syntax of regular expressions.
🌐
Analytics Vidhya
analyticsvidhya.com › home › regular expressions: how can they transform your coding efficiency?
Regular Expressions: Applications & Implementation in Python
April 29, 2025 - Backslash (\): It’s used to escape a special character, turning it into a literal. For example, \\. matches a literal dot. Pipe (|): It acts like a logical OR. Matches the pattern before or the pattern after it. Parentheses ((…)): A quantifier can specify how many times parts of a RegEx, grouped together, should repeat. Regular expressions is provided by many programming languages, such as python, java, javascript, etc.
🌐
Python Course
python-course.eu › advanced-python › advanced-regular-expressions.php
16. Advanced Regular Expressions | Advanced | python-course.eu
Sometimes we need a choice between several regular expressions. It's a logical "or" and that's why the symbol for this construct is the "|" symbol. In the following example, we check, if one of the cities London, Paris, Zurich, Konstanz Bern or Strasbourg appear in a string preceded by the word "location":
🌐
Python for Everybody
py4e.com › html3 › 11-regex
Regular Expressions
Notice that on the [email protected] lines, our regular expression eliminated two letters at the end of the string (“>;”). This is because when we append [a-zA-Z] to the end of our regular expression, we are demanding that whatever string the regular expression parser finds must end with a letter. So when it sees the “>” at the end of “sakaiproject.org>;” it simply stops at the last “matching” letter it found (i.e., the “g” was the last good match). Also note that the output of the program is a Python list that has a string as the single element in the list.
🌐
Built In
builtin.com › articles › python-re-match
Python re.match() and re.sub() Explained | Built In
So, this example finds phone numbers in the 123-456-7890 format and converts them to (123) 456-7890. ... Contact me at (123) 456-7890 or (987) 654-3210. ... (): Used for capturing groups, allowing us to extract parts of the match and reference ...
Find elsewhere
🌐
Scaler
scaler.com › home › topics › python › regular expression in python
Python RegEx | Regular Expression - Scaler Topics
February 11, 2022 - These are supported by many languages such as python, java, R etc.Most common uses of regular expressions are: Finding patterns in a string or file.(Ex: find all the numbers present in a string) Replace a part of the string with another string. Search substring in string or file. Split string into substrings. Validate email format. We will see examples of above mentioned uses in detail.
🌐
W3Schools
w3schools.com › python › python_regex.asp
Python RegEx
You can add flags to the pattern when using regular expressions. A special sequence is a \ followed by one of the characters in the list below, and has a special meaning: A set is a set of characters inside a pair of square brackets [] with a special meaning: The findall() function returns a list containing all matches. ... The list contains the matches in the order they are found.
🌐
Programiz
programiz.com › python-programming › regex
Python RegEx (With Examples)
If you already know the basics of RegEx, jump to Python RegEx. To specify regular expressions, metacharacters are used. In the above example, ^ and $ are metacharacters.
🌐
Google
developers.google.com › google for education › python › python regular expressions
Python Regular Expressions | Python Education | Google for Developers
So, for example, use \. to match a period or \\ to match a slash. If you are unsure if a character has special meaning, such as '@', you can try putting a slash in front of it, \@. If its not a valid escape sequence, like \c, your python program will halt with an error. Joke: what do you call a pig with three eyes? piiig! The basic rules of regular expression search for a pattern within a string are:
🌐
Python documentation
docs.python.org › 3 › library › re.html
re — Regular expression operations
4 days ago - Special characters either stand for classes of ordinary characters, or affect how the regular expressions around them are interpreted. Repetition operators or quantifiers (*, +, ?, {m,n}, etc) cannot be directly nested. This avoids ambiguity with the non-greedy modifier suffix ?, and with other modifiers in other implementations. To apply a second repetition to an inner repetition, parentheses may be used. For example, the expression (?:a{6})* matches any multiple of six 'a' characters.
🌐
Tutorialspoint
tutorialspoint.com › home › python › python regular expressions
Python Regular Expressions
February 21, 2009 - This method returns modified string. import re phone = "2004-959-559 # This is Phone Number" # Delete Python-style comments num = re.sub(r'#.*$', "", phone) print ("Phone Num : ", num) # Remove anything other than digits num = re.sub(r'\D', ...
🌐
Python documentation
docs.python.org › 3 › howto › regex.html
Regular Expression HOWTO — Python 3.14.3 documentation
For example, [\s,.] is a character class that will match any whitespace character, or ',' or '.'. The final metacharacter in this section is .. It matches anything except a newline character, and there’s an alternate mode (re.DOTALL) where it will match even a newline. . is often used where you want to match “any character”. Being able to match varying sets of characters is the first thing regular expressions can do that isn’t already possible with the methods available on strings.
🌐
Real Python
realpython.com › regex-python
Regular Expressions: Regexes in Python (Part 1) – Real Python
October 21, 2023 - This allows you to specify documentation inside a regex in Python, which can be especially useful if the regex is particularly long. ... Specifies a set of alternatives on which to match. An expression of the form <regex1>|<regex2>|...|<regexn> matches at most one of the specified <regexi> expressions:
🌐
PyPI
pypi.org › project › regex
regex · PyPI
In the regex (\s+)(?|(?P<foo>[A-Z]+)|(\w+) (?P<foo>[0-9]+) there are 2 groups: ... If you want to prevent (\w+) from being group 2, you need to name it (different name, different group number).
      » pip install regex
    
Published   Feb 28, 2026
Version   2026.2.28
🌐
StrataScratch
stratascratch.com › blog › mastering-python-regex-a-deep-dive-into-pattern-matching
Mastering Python RegEx: A Deep Dive into Pattern Matching - StrataScratch
July 21, 2023 - Literal characters are the simplest form of pattern matching in regular expressions. They match themselves exactly and do not have a special meaning. For example, the regular expression python will match the string python exactly.
🌐
NTU Singapore
www3.ntu.edu.sg › home › ehchua › programming › howto › Regexe.html
Regular Expression (Regex) Tutorial
You can also write \d+, where \d is known as a meta-character that matches any digit (same as [0-9]). There are more than one ways to write a regex! Take note that many programming languages (C, Java, JavaScript, Python) use backslash \ as the prefix for escape sequences (e.g., \n for newline), and you need to write "\\d+" instead. See "Python's re module for Regular Expression" for full coverage.
🌐
Automate the Boring Stuff
automatetheboringstuff.com › 3e › chapter9.html
Chapter 9 - Text Pattern Matching with Regular Expressions, Automate the Boring Stuff with Python, 3rd Ed
For example, the characters \d in a regex stand for a decimal numeral between 0 and 9. Python uses the regex string r'\d\d\d-\d\d\d-\d\d\d\d' to match the same text pattern the previous is_phone_number() function did: a string of three numbers, a hyphen, three more numbers, another hyphen, ...