Python string substitution, regular lookup substitution

Source: Internet
Author: User

ImportReif __name__=="__main__": URL="\ deded<a href =""> This is the first link </a><a href =""> This is a second link </a> \ n"    #remove \ none = Url.replace ("\ n","")    #Remove both spacesboth =One.strip ()#The regular match Re.match matches from the beginning of the string. three = Re.match (r"(<a ([^>]*?) >) (. *?) (</a>)", both)ifThree is  notNone:arr=three.groups ()Print(Arr[0] +"hahaha"+ arr[3])    #The regular lookup contains </a>,re.search to find the entire string, as long as it matches. Re.match is searched from the string, if there is no match at the beginning, it is not consideredresult = Re.search ("</a>", both). Group ()Print(Result)#regular Find and replace    Print(Re.sub (Re.compile (R"<a.*?</a>", Re. S),"", both))

Python string substitution, regular lookup substitution

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.