How to compare two strings using regex in Python?


We can compare given strings using the following code

Example

import re
s1 = 'Pink Forest'
s2 = 'Pink Forrest'
if bool(re.search(s1,s2))==True:
   print 'Strings match'
else:
   print 'Strings do not match'

Output

This gives the output

Strings do not match

Updated on: 19-Dec-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements