How to Use Regular Expressions in Python


In this example we will show how to use the regular expressions in Python.

Source Code

import re
# imported the re module, you can start using regular expressions

str1 = 'I love Python'
r = re.match('I', str1)

if r:
    print('We have a match!')
else:
    print('No match!')

Output:

We have a match!
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments