I have two strings. I would like to know the upto how many characters are similar in both the strings.

E.x: lets say 'xyzabc', 'xyzadh'. I would like to know if there is a function that can give the index at which the similarity is breaking. In this case it would be 4 because upto 'xyza' the strings are same. If the strings are 'xyzabc', 'xymabc' then the result should be 2.

I would like to use it as select func('xyzabc', 'xyzwer'); to get the required answer. Kinldy let me know if there is a function existing in SQL.

What version of Sybase are you using? The answer to your question is that you need regular expressions . . . but they are not in all versions of the product.
–
Gordon LinoffAug 3 '12 at 14:53

Hi Gordon, I am not sure about the version. I will check and let you know. Meanwhile, if we assume that my version supports regular expressions, then what could be the method to check the similarity.
–
Goje87Aug 3 '12 at 16:56

1 Answer
1

One way to do this is with regular expressions. Here is the idea. You would use regexp_substr(). The regular expression would, in your example, be 'xyzwer|xyzwe|xyzw|xyz|xy|x'. You would then measure the length of the matching substring. In other words, you need to convert one of the strings to a regular expression.