This is a creation in Article, where the information may have evolved or changed.
Original link: http://outofmemory.cn/code-snippet/2092/ Usage-golang-regular-expression-regexp-quchu-html-css-script-code-jin-maintain-page-wenzi
PackageMainImport ( "FMT" "Io/ioutil" "Net/http" "RegExp" "Strings" )Func main() {resp,Err:=http.Get("Http://www.baidu.com") //RESP, err: = http. Get ("http://www.163.com") ifErr!= Nil {FMT.Println("http GET error.") }Defer resp.Body.Close()Body,Err:=Ioutil.ReadAll(resp.Body) ifErr!= Nil {FMT.Println("http Read error") }src:= string(Body) //change HTML tags to lowercaseRe, _ :=RegExp.Compile("\\<[\\s\\s]+?\\>")src=Re.Replaceallstringfunc(src,Strings.ToLower) //Remove styleRe, _ =RegExp.Compile("\\<style[\\s\\s]+?\\</style\\>")src=Re.replaceallstring(src, "") //Remove ScriptRe, _ =RegExp.Compile("\\<script[\\s\\s]+?\\</script\\>")src=Re.replaceallstring(src, "") //Remove all HTML code within the angle brackets and replace with newline charactersRe, _ =RegExp.Compile("\\<[\\s\\s]+?\\>")src=Re.replaceallstring(src, "\ n") //Remove continuous line breaksRe, _ =RegExp.Compile("\\s{2,}")src=Re.replaceallstring(src, "\ n")FMT.Println(Strings.Trimspace(src)) }