javascript - Can someone tell me the purpose of the second capture group in the jQuery rts regular expression? -
in jeff roberson's jquery regular expressions review proposes changing rts regular expression in jquery's ajax.js /(\?|&)_=.*?(&|$)/ /([?&])_=[^&\r\n]*(&?)/. in both versions, purpose of second capture group? code replacement of current random timestamp new random timestamp:  
var ts = jquery.now(); // try replacing _= if there var ret = s.url.replace(rts, "$1_=" + ts + "$2");   doesn't replace matches? thinking same:
var ret = s.url.replace(/([?&])_=[^&\r\n]*/, "$1_=" + ts);   can explain purpose of second capture group?
it's pick next delimiter in query string on url, still works query string. if url is
http://foo.bar/what/ever?blah=blah&_=12345&zebra=banana   then second group picks "&" before "zebra".
that's awesome blog post way , should read it.
edit — think it, i'm not sure why it's necessary bother replacing second delimiter. in "fixed" expression, greedy * pick whole parameter value , stop @ delimiter (or end of string) anyway.
Comments
Post a Comment