-
Notifications
You must be signed in to change notification settings - Fork 3
Regular Expressions
surendrabisht edited this page Jul 27, 2020
·
1 revision
import re
import this
pattern=r"sonu"
print(re.match(pattern,"Hi this is sonu bisht from dehradun. \nsonu"))
print(re.search(pattern,"Hi this is surendra bisht from dehradun. \nsonu"))
print(re.findall(pattern,"Hi this is sonu bisht from dehradun. \nsonuBisht"))
#### sub function replaces the searched text.
str = "My name is David. Hi David."
pattern = r"David"
newstr = re.sub(pattern, "Surendra", str)
print(newstr)
pattern = r"[A-Z][A-Z][0-9]"
if re.search(pattern, "LS8"):
print("Match 1")
pattern = r"a(bc)(de)(f(g)h)i"
groups() will print all groups catured. groups(0) will show whole string matching. groups(1) shows first group.
Keep Learning. Never Settle! 😊
- Home
- 1.Introduction To Python
- 2. DataTypes
- 3. Strings and Slicing of collection
- 4.If else & Loops
- 5. Break, continue, pass
- 6. Functions
- 7. Modules
- 8. Clarifying basics
- 9. File Handling
- 10. Exception Handling
- 11. Dig into Collections
- 12. Iterators, Generators and list comprehension
- 13. lambdas , map, filter and other concepts
- 14. args, kwargs an default parameters
- 15. Functional Programming
- 16. OOPs