🌐
W3Schools
w3schools.com › python › python_regex.asp
Python RegEx
RegEx can be used to check if a string contains the specified search pattern. Python has a built-in package called re, which can be used to work with Regular Expressions.
🌐
Python documentation
docs.python.org › 3 › howto › regex.html
Regular expression HOWTO — Python 3.14.7 documentation
Let’s take an example: \w matches any alphanumeric character. If the regex pattern is expressed in bytes, this is equivalent to the class [a-zA-Z0-9_]. If the regex pattern is a string, \w will match all the characters marked as letters in ...
Discussions

9 Practical Examples of Using Regular Expressions in Python

There are some ugly regexes in that. Matching minutes as 0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9] when you could just write [0-5]\d or [0-5][0-9] is why people think regexes are unreadable.

More on reddit.com
🌐 r/Python
4
0
April 19, 2023
Python regular expressions, REGEX
Your regex is: First Name: (.*?) Last Name: (.*?) You are searching for the left-most match in the input: First Name: Gideon Last Name: Asiak So the regex engine consumes First Name:, then consumes as little as possible until Last Name: matches (saving Gideon in group 1), and then gets to match .*? against the remaining Asiak. As this is a non-greedy match, this pattern will consume as little as possible until we get a match. The pattern is already satisfied when consuming zero characters, so group 2 will contain the empty string. How to fix this: If you want to make sure that the entire string matches a pattern, use the fullmatch() function. Equivalently, you could anchor the pattern at the end of the string via the \z assertion. You could use a greedy match for the second group, e.g. (.*). It will consume as much as possible. In practice, if we can assume that each name won't contain spaces, I might write the pattern like this: First Name: (\S+) Last Name: (\S+). That is, use a more specific character class like \S (all non-space characters), and a quantifier that expects at least one character. More on reddit.com
🌐 r/learnpython
12
1
November 25, 2025
Python match a string with regex - Stack Overflow
I need a python regular expression to check if a word is present in a string. The string is separated by commas, potentially. So for example, line = 'This,is,a,sample,string' I want to search bas... More on stackoverflow.com
🌐 stackoverflow.com
how hard is it to learn regex... is it worth learning?
Regex is a mini-programming language by itself. It is powerful and useful if you are doing a lot of text processing. Like a programming language, it will take time and practice to get comfortable with it. There are various online tools that can help you with learning, writing and debugging regex. regex101 — visual aid and online testing tool for regular expressions, select flavor as Python before use debuggex — railroad diagrams for regular expressions, select flavor as Python before use Other useful resources: Awesome Regex — curated collection of libraries, tools, frameworks and software PythonVerbalExpressions — construct regular expressions with natural language terms CommonRegex — collection of common regular expressions stackoverflow: regex FAQ More on reddit.com
🌐 r/learnpython
56
83
January 22, 2021
🌐
GeeksforGeeks
geeksforgeeks.org › python › regular-expression-python-examples
Python RegEx - GeeksforGeeks
August 14, 2025 - import re regex = r"([a-zA-Z]+) (\d+)" match = re.search(regex, "I was born on June 24") if match: print("Match at index %s, %s" % (match.start(), match.end())) print("Full match:", match.group(0)) print("Month:", match.group(1)) print("Day:", match.group(2)) else: print("The regex pattern does not match.") ... Metacharacters are special characters in regular expressions used to define search patterns. The re module in Python supports several metacharacters that help you perform powerful pattern matching. ... The backslash (\) makes sure that the character is not treated in a special way. This can be considered a way of escaping metacharacters. For example, if you want to search for the dot(.) in the string then you will find that dot(.) will be treated as a special character as is one of the metacharacters (as shown in the above table).
🌐
Google
developers.google.com › google for education › python › python regular expressions
Python Regular Expressions | Python Education | Google for Developers
\d -- decimal digit [0-9] (some older regex utilities do not support \d, but they all support \w and \s) ^ = start, $ = end -- match the start or end of the string · \ -- inhibit the "specialness" of a character. 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 ...
🌐
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.
🌐
Python documentation
docs.python.org › 3 › library › re.html
re — Regular expression operations
The value of endpos which was passed to the search() or match() method of a regex object. This is the index into the string beyond which the RE engine will not go. ... The integer index of the last matched capturing group, or None if no group was matched at all. For example, the expressions (a)b, ((a)(b)), and ((ab)) will have lastindex == 1 if applied to the string 'ab', while the expression (a)(b) will have lastindex == 2, if applied to the same string.
🌐
NTU Singapore
www3.ntu.edu.sg › home › ehchua › programming › howto › Regexe.html
Regular Expression (Regex) Tutorial
For examples, \+ matches "+"; \[ matches "["; and \. matches ".". Regex also recognizes common escape sequences such as \n for newline, \t for tab, \r for carriage-return, \nnn for a up to 3-digit octal number, \xhh for a two-digit hex code, \uhhhh for a 4-digit Unicode, \uhhhhhhhh for a 8-digit Unicode. $ python3 >>> import re # Need module 're' for regular expression # Try find: re.findall(regexStr, inStr) -> matchedStrList # r'...' denotes raw strings which ignore escape code, i.e., r'\n' is '\'+'n' >>> re.findall(r'a', 'abcabc') ['a', 'a'] >>> re.findall(r'=', 'abc=abc') # '=' is not a special regex character ['='] >>> re.findall(r'\.', 'abc.com') # '.' is a special regex character, need regex escape sequence ['.'] >>> re.findall('\\.', 'abc.com') # You need to write \\ for \ in regular Python string ['.']
Find elsewhere
🌐
Medium
medium.com › @ebojacky › the-very-bare-minimum-essentials-for-regular-expressions-in-python-54e78c10b649
The Very Bare Minimum Essentials for Regular Expressions in Python | by Ebo Jackson | Medium
June 2, 2025 - The re module provides a robust framework for working with regex, enabling developers to handle tasks like validation, parsing, and cleaning with precision. This article covers the essential concepts and techniques you need to master regex in Python, organized by priority and complexity, with practical examples to illustrate each topic.
🌐
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.
🌐
Real Python
realpython.com › regex-python
Regular Expressions: Regexes in Python (Part 1) – Real Python
May 21, 2026 - For example, rather than searching for a fixed substring like '123', suppose you wanted to determine whether a string contains any three consecutive decimal digit characters, as in the strings 'foo123bar', 'foo456bar', '234baz', and 'qux678'. Strict character comparisons won’t cut it here. This is where regexes in Python come to the rescue.
🌐
Rexegg
rexegg.com › regex-python.php
Python Regex Tutorial
Python Regex Tutorial. Discusses the Python re and regex classes, provides working code for matching, replacing and splitting.
🌐
AppSignal
blog.appsignal.com › home › python › python regex: how to use re.search, re.match, and re.findall
Python Regex: How to Use re.search, re.match, and re.findall | AppSignal Blog
January 15, 2025 - Now, let's examine some real-world scenarios to give a more practical idea of how and when to use regex in Python. Regular expressions are commonly used to validate data formats such as email addresses, phone numbers, and dates. ... pattern = r"^[\w\.-]+@[\w\.-]+\.\w+$" email = "example@example.com" match = re.match(pattern, email) print(bool(match))
🌐
Reddit
reddit.com › r/python › 9 practical examples of using regular expressions in python
r/Python on Reddit: 9 Practical Examples of Using Regular Expressions in Python
April 19, 2023 - Matching minutes as 0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9] when you could just write [0-5]\d or [0-5][0-9] is why people think regexes are unreadable.
🌐
Medium
medium.com › @smrati.katiyar › python-regular-expressions-a-beginners-tutorial-fd3b509876c0
Python Regular Expressions: A Beginner’s Tutorial | by smrati katiyar | Medium
October 22, 2024 - You can group parts of the regex using parentheses and extract them using groups. let’s see how grouping works and how we can use it to capture parts of a match. import re text = "My email is example@domain.com." pattern = r"(\w+)@(\w+)\.(\w+)" # Captures parts of an email address match = re.search(pattern, text) if match: print(match.group()) # Output: example@domain.com (entire match) print(match.group(1)) # Output: example (first group) print(match.group(2)) # Output: domain (second group) print(match.group(3)) # Output: com (third group)
🌐
Medium
medium.com › techtofreedom › 9-practical-examples-of-using-regular-expressions-in-python-1b4f8da5cdab
9 Practical Examples of Using Regular Expressions in Python | by Yang Zhou | TechToFreedom | Medium
April 13, 2023 - Checking the validity of an email address is a classic use case of regex. ... import re def val_email(email): pattern = r"^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,}$" if re.match(pattern, email): print("Valid email address:)") else: print("Invalid email address!!") val_email(email="elon@example.com") # Valid email address:) val_email(email="elonexample.com") # Invalid email address!! val_email(email="elon@example.c") # Invalid email address!! ... Helping developers stay ahead in Python and AI.
🌐
Reddit
reddit.com › r/learnpython › python regular expressions, regex
r/learnpython on Reddit: Python regular expressions, REGEX
November 25, 2025 -

Hello my friend! I am learning python using the popular book, Automate the boring stuff book and I came accross the regeneration class. I tried non-greedy matching the two groups of characters in a string. The group method returned the first group but didnt the second group. I asked chat gpt and it said my code is fine. It gave me some probable causes pf such an issue that there us a newline but that isn't so. Attached is my code.

Will appreciate your assistance and comments. Thank you

  1. name_regex1 = re.compile(r"First Name: (.?) Last Name: (.?)")

  2. name2 = name_regex1.search("First Name: Gideon Last Name: Asiak")

  3. print(name2.group(2))

Sorry I couldn't attach the screenshot, but this is the code up here.(please know that there are no newline, each statement is in its line)

NOTE: there is an asterisk between the '.' and '?'. I dont know why when I post it dissapears.

Top answer
1 of 4
6
Your regex is: First Name: (.*?) Last Name: (.*?) You are searching for the left-most match in the input: First Name: Gideon Last Name: Asiak So the regex engine consumes First Name:, then consumes as little as possible until Last Name: matches (saving Gideon in group 1), and then gets to match .*? against the remaining Asiak. As this is a non-greedy match, this pattern will consume as little as possible until we get a match. The pattern is already satisfied when consuming zero characters, so group 2 will contain the empty string. How to fix this: If you want to make sure that the entire string matches a pattern, use the fullmatch() function. Equivalently, you could anchor the pattern at the end of the string via the \z assertion. You could use a greedy match for the second group, e.g. (.*). It will consume as much as possible. In practice, if we can assume that each name won't contain spaces, I might write the pattern like this: First Name: (\S+) Last Name: (\S+). That is, use a more specific character class like \S (all non-space characters), and a quantifier that expects at least one character.
2 of 4
3
Hey there! The regeneration regular expressions (regex) library lets you use patterns (regular expressions) to search for matches in a piece of text. Your regular expression r'First Name: (.?) Last Name: (.?) is close, but not quite correct. To find the names 'Gideon' and 'Asiak', replace the ? with a +. (): Create a pattern matching group .: Match any character +: Match any length from re import compile name_regex1 = compile(r'First Name: (.+) Last Name: (.+)') name2 = name_regex1.search('First Name: Gideon Last Name: Asiak') print(name2.group(1)) # 'Gideon' print(name2.group(2)) # 'Asiak'
🌐
Chroma
trychroma.com
Chroma - open-source search infrastructure for AI
Regex Search Support · Search using regular expressions with new operators. Jun 2025 · JavaScript Client V3 · Complete rewrite with reduced bundle size. Jun 2025 · We’re looking for curious people who are dedicated to becoming world-class at their craft to join our team. See open roles · Get started · Get up and running in 30 seconds or less with $5 in free credits. Quick Start · PythonPython getting started docs → ·
🌐
regex101
regex101.com › library
Security check · regex101
Please complete this security check to continue to regex101.
🌐
PyPI
pypi.org › project › yt-dlp
yt-dlp · PyPI
Also embeds chapters/infojson if present unless --no-embed-chapters/--no-embed-info-json are used (Alias: --add-metadata) --no-embed-metadata Do not add metadata to file (default) (Alias: --no-add-metadata) --embed-chapters Add chapter markers to the video file (Alias: --add-chapters) --no-embed-chapters Do not add chapter markers (default) (Alias: --no-add-chapters) --embed-info-json Embed the infojson as an attachment to mkv/mka video files --no-embed-info-json Do not embed the infojson as an attachment to the video file --parse-metadata [WHEN:]FROM:TO Parse additional metadata like title/artist from other fields; see "MODIFYING METADATA" for details. Supported values of "WHEN" are the same as that of --use-postprocessor (default: pre_process) --replace-in-metadata [WHEN:]FIELDS REGEX REPLACE Replace text in a metadata field using the given regex.