Regexp finding longest common prefix of two strings
Question:
Is there a regexp which would find longest common prefix of two strings? And if this is not solvable by one regexp, what would be the most elegant piece of code or oneliner using regexp (perl, ruby, python, anything).
PS: I can do this easily programatically, I am asking rather for curiosity, because it seems to me that this could be solveable by regexp.
PPS: Extra bonus for O(n) solution using regexps. Come on, it should exist!
Answers:
If there’s some character that neither string contains —, say,
Is there a regexp which would find longest common prefix of two strings? And if this is not solvable by one regexp, what would be the most elegant piece of code or oneliner using regexp (perl, ruby, python, anything).
PS: I can do this easily programatically, I am asking rather for curiosity, because it seems to me that this could be solveable by regexp.
PPS: Extra bonus for O(n) solution using regexps. Come on, it should exist!
If there’s some character that neither string contains —, say,