Home >Web Front-end >HTML Tutorial >Three functions commonly used when processing HTML text_html/css_WEB-ITnose
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;}