var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
html: function( value ) {
if ( value === undefined ) {
return this[0] && this[0].nodeType === 1 ?
this[0].innerHTML.replace(rinlinejQuery, "") :
null;
// See if we can take a shortcut and just use innerHTML
}
Does it match code such as jQuery11="11"?
And why is it needed in the html() function?
OK, so first off we have
jQuery\d+which is just ‘jQuery’ followed by one or more numerical digits (\dis the same as[01-9]).Then we have
="which are just literals here, so we’re matching anything that has ‘jQuery’, then at least one number, then ‘=”‘.Next, the
(...|...)construct is an Or, so it matches either the expression before the vertical bar|, or the expression after it. In this case, those expressions are\d+andnull, so our query matches any string that consists of ‘jQuery’, at least one number, ‘=”‘, and then either at least one number, or the string ‘null’. This is followed by a"literal.The only thing left as part of the expression itself is the
?:found just after the opening parenthesis. Normally, anything in parentheses in a regular expression gets saved, so that you can refer to it in the replacement string with$nwherenis a number referring to which match you’re referring to. The?:to start the parenthetical in this case prevents that from happening, so that the parentheses can be used to group the options for the Or without wasting time or memory remembering the value of the match.Finally, regular expressions are enclosed in forward slashes
/, and this one has thegswitch, which indicates a global search.So what we have is ‘jQuery’, one or more numbers, ‘=”‘, one or more numbers or ‘null’, ‘”‘.
To answer your second question, yes, this pattern would match that string.
I’m afraid I do not know why jQuery’s html function needed to remove that particular string from
this[0].innerHTML(which is what thereplacefunction is doing), but based on the comment it looks like they were using the string to test whether or notinnerHTMLwas valid and functional (which it is not on all browsers)?