Using $ to match end-of-input gives a zero-length match everywhere else but no evidence of a match with WebKit:
function showBug() {
Result = "the end.".replace( /(end\.)([\s]|$)?/img, makeChange );
return;
}
function makeChange() {
for ( var i = 0; i < arguments.length; i += 1 ) {
document.write( "arg" + i + " -->" + arguments[ i ] + "<--" + "<BR>" );
}
}
gives
arg0 -->end.<--
arg1 -->end.<--
arg2 -->undefined<--
arg3 -->4<--
arg4 -->the end.<--
for AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.5 Safari/534.55.3
,
also for AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19
.
Opera (Presto/2.10.229 Version/11.62
), FF (Gecko/20100101 Firefox/10.0.2
) and IE (MSIE 8.0; Trident/4.0
) all give
arg0 -->end.<--
arg1 -->end.<--
arg2 --><--
arg3 -->4<--
arg4 -->the end.<--
which means I can detect the match in $2 (it's actually about interpreting a trailing dot on a url as not being part of the url). I'm currently adding a trailing space for WebKit, and taking it off afterwards, but I'm wondering if anyone has a better solution and can confirm I should raise this as a bug.
|
in that expression. So you could write it/(end\.)([\s])?$/
to match something before end-of-line. Second, are you trying to match 0 or 1 of 's' and '\' or are you trying to match whitespace\s
(no brackets)? jsfiddle.net/2hZdT – Mathletics Apr 27 '12 at 17:13