I have a code that looks like this
import re
s = "farmer’s boy of s...=--ixpence."
b = "farmer's boy of s...=--ixpence."
s_replaced = re.sub("[^a-zA-Z' ]+", '', s)
b_replaced = re.sub("[^a-zA-Z' ]+", '', b)
print(s_replaced)
print(b_replaced)
>>> farmers boy of sixpence
>>> farmer's boy of sixpence
I was trying to write a code that eliminates all punctuation except for apostrophe, and I don't understand why regex is returning different results for a same set of string. Why is this happening?
’is not the same as'.>>> "farmer’s boy of s...=--ixpence." == "farmer's boy of s...=--ixpence." Falsesandb, something likeif s == b:, to ensure both strings are the same.