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 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']
  • The pattern r"[+-]?\d+(\.\d+)?" matches numbers like -3.5 and +27.85. It can handle both signed and unsigned numbers with a decimal point.