DeveloperBreeze

Regular Expression Tutorial Development Tutorials, Guides & Insights

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

Understanding Regular Expressions with `re` in Python

Tutorial October 24, 2024
python

import re

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

# Example text with both integers and floating-point numbers
text = "The values are -20, 15.75, +7, and 3.1415."

matches = re.findall(pattern, text)
print(matches)  # Output: ['-20', '15.75', '+7', '3.1415']
  • This pattern finds both integer (-20, +7) and floating-point (15.75, 3.1415) numbers, handling both signed and unsigned numbers.