var findDupSubstring = function(a, b){ if (a.length < b.length) {var t=a;a=b;b=t;} var ary = b.split("").map(function(c){return (/^\W$/).test(c) ? "\\"+c : c;}); var reStr = ary.pop(); var buf = [reStr, reStr = ary.pop() + reStr + "?"]; for (var i=ary.length; i-->0; ) { buf.push(reStr = ary[i] + "(?:" + reStr + ")?"); } var matches = a.match(new RegExp(buf.reverse().join("|"), "g")); return matche