find whether the string starts and ends with the same word
- by Ajax
I am trying to check whether the string starts and ends with the same word. egearth.
s=raw_input();
m=re.search(r"^(earth).*(earth)$",s)
if m is not None:
print "found"
my problem is when the string consists only of one word eg: earth
At present I have hard coded this case by
if m is not None or s=='earth':
print "found"
Is there any other way to do this?
EDIT:
words in a string are separated by spaces. looking for a regex solution
some examples:
"earth is earth" ,"earth", -- valid
"earthearth", "eartheeearth", "earth earth mars" -- invalid