Golang Html Regular

Source: Internet
Author: User
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))  } 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.