How do I match exact words in Python?
Using regular expressions to match exact words in python.
What is RegEx(Regular Expressions): A RegEx, or Regular Expression, maybe a sequence of characters that forms a search pattern.
RegEx can be used to check whether a string contains a specified search pattern or not.
Python has an in-built package called re module. re module works as a regular expression.
Firstly, Import the re module
- import re
- str = "This is python re module"
- x = re.search("re", str)
- if x:
- print("YES! We have a match!")
- else:
- print("No match")
Comments
Post a Comment