Syntax error How to compare two strings using regex in 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
Updated on: 2019-12-19T08:49:48+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements