How to detect identical part(s) inside string?
- by Horace Ho
I try to break down the http://stackoverflow.com/questions/2711961/decoding-algorithm-wanted question into smaller questions. This is Part I.
Question:
two strings: s1 and s2
part of s1 is identical to part of s2
space is separator
how to extract the identical part(s)?
example 1:
s1 = "12 November 2010 - 1 visitor"
s2 = "6 July 2010 - 100 visitors"
the identical parts are "2010", "-", "1" and "visitor"
example 2:
s1 = "Welcome, John!"
s2 = "Welcome, Peter!"
the identical parts are "Welcome," and "!"
Python and Ruby preferred. Thanks