Previous Post :
Python #22-Regex match() and search() in Python
Next Post :
Coming soon........
re.findall():
- It find all sub strings where the RE matches, and return them as a list. This function is used to catch all the matching patterns in the strings.
Note Worthy: re.match() + re.search() = re.findall()
Syntax:
re.findall(pattern, string)
Source Code:
import re
variable = re.findall(r"Google", "Google Bird learn around Google and gives the best contents to the viewrs")
print variable
Output:
['Google', 'Google']
re.sub():
- This is used to search a pattern in the string an replace with the new sub string.
Syntax:
re.sub(pattern, replacement_string, string )
Source Code:
import re
variable = re.sub(r"viewers","Learners to learn easily", "Google Bird learn around Google and gives the best contents to the viewers")
print variable
Output:
Google Bird learn around google and gives the best contents to the Learners to learn easily
Need Python Compiler To code.Check here.
Don't forget to Follow .
Thanks and regards,
Tech Bird
Comments