Computer >> Computer tutorials >  >> Programming >> Python

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