DeveloperBreeze

Re Module Development Tutorials, Guides & Insights

Unlock 2+ expert-curated re module tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your re module skills on DeveloperBreeze.

Understanding Regular Expressions with `re` in Python

Tutorial October 24, 2024
python

Next, we will use a pattern to match floating-point numbers, which may or may not have a decimal part.

import re

# Pattern to match floating-point numbers
pattern = r"[+-]?\d+(\.\d+)?"

# Example text containing floating-point numbers
text = "Temperatures range from -3.5 to +27.85 degrees."

matches = re.findall(pattern, text)
print(matches)  # Output: ['-3.5', '+27.85']

Python Regular Expressions (Regex) Cheatsheet

Cheatsheet August 03, 2024
python

match = re.search(r'(\d+)', 'The price is 100 dollars')
if match:
    print(match.group())  # Output: 100
    print(match.start())  # Output: 12
    print(match.end())    # Output: 15
    print(match.span())   # Output: (12, 15)
email_pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
email = 'example@example.com'
if re.match(email_pattern, email):
    print('Valid email')
else:
    print('Invalid email')