65. Regular Expressions with re
Regular Expressions with re: Using the re module for pattern matching and string manipulation
re: Using the re module for pattern matching and string manipulation1. Basic Matching with re.match() and re.search()
re.match() and re.search()import re
# re.match() example
result = re.match(r'hello', 'hello world')
if result:
print("Match found:", result.group())
else:
print("No match")
# re.search() example
result = re.search(r'world', 'hello world')
if result:
print("Search found:", result.group())
else:
print("No search match")2. Finding All Matches with re.findall()
re.findall()3. Replacing Text with re.sub()
re.sub()4. Compiling Regular Expressions with re.compile()
re.compile()5. Using Groups with re.search()
re.search()6. Matching at the Start or End of a String
7. Using re.split() to Split a String
re.split() to Split a String8. Using Wildcards with .
.9. Using Character Classes
10. Using Quantifiers
11. Anchoring with Word Boundaries \b
\b12. Case-Insensitive Matching with re.IGNORECASE
re.IGNORECASESummary of Key Features:
Last updated