Home >Web Front-end >HTML Tutorial >Three functions commonly used when processing HTML text_html/css_WEB-ITnose

Three functions commonly used when processing HTML text_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:44:281100browse

Today I talked with a friend about strengthening regular training for front-end engineers. So I will share three functions that are most commonly used when filtering HTML text. These functions are processed using regular expressions.

/* * 去掉HTML标签 */function stripHTML(oldString) {    return oldString.replace(/<\/?[^>]+>/gi, "");}/* * 去掉<br> */function stripBR(oldString) {    return oldString.replace(/<br.{0,}?>/gi, "");}/* * 去掉全角空格和半角空格 */function stripSpace(string) {    var tempstr;    tempstr = string.replace(/(^\s+)|(\s+$)/g, "");    tempstr = tempstr.replace(/(^ +)|( +$)/g, "");    return tempstr;}
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