Home  >  Article  >  Web Front-end  >  Usage of JavaScript replace(rgExp,fn) regular replacement_Basic knowledge

Usage of JavaScript replace(rgExp,fn) regular replacement_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 18:33:251137browse

The code is as follows:

Copy code The code is as follows:

var rxhtmlTag = /(<([ w:] )[^>]*?)/>/g,
rselfClosing = /^(?:area|br|col|embed|hr|img|input|link|meta|param)$/ i,
fcloseTag = function(all, front, tag) {
return rselfClosing.test(tag) ?
  all :
front ">";
};
//Convert "Xhtml" style tags to standard HTML tags
//For example, is
elem = elem.replace (rxhtmlTag, fcloseTag);


Mainly look at fcloseTag = function(all, front, tag){}
The first parameter all is the entire string matched by rxhtmlTag
The second parameter front is the content in the first left bracket "(" matched by rxhtmlTag
The third parameter tag is the content in the second left bracket "(" matched by rxhtmlTag

The number of parameters is proportional to the number of left brackets in the regular expression, and the position of the parameters from left to right corresponds to the position of the left bracket.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn