DeveloperBreeze

Groups Development Tutorials, Guides & Insights

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

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')