How to detect identical part(s) inside string?
Posted
by Horace Ho
on Stack Overflow
See other posts from Stack Overflow
or by Horace Ho
Published on 2010-04-26T09:54:06Z
Indexed on
2010/04/26
10:23 UTC
Read the original article
Hit count: 249
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
© Stack Overflow or respective owner