Python shell regular expression captures complex string-specific substrings

Source: Internet
Author: User

Suddenly I realized a little bit of skill, first written here, lest later forget again.


There is a string s= ' style= ' border-top:1px dotted #DDD; text-align:left;padding-left:5px; " ><a href= "' +e.url+ '" target= "_blank" I want to take ddd out of regular expressions

You can use this string with the # and before and after the DDD, as delimiters. Examples are as follows


Import re

s= "style=" border-top:1px dotted #DDD; text-align:left;padding-left:5px; " ><a href= "' +e.url+ '" target= "_blank"

Reg=r ' [#;] + ' #关键是规则

Li=re.split (Reg,s)

Print (LI)

The results of the operation are as follows:

[' style= ' border-top:1px dotted ', ' DDD ', ' text-align:left ', ' padding-left:5px ', ' ><a href= ' \ ' +e.url+\ ' "target=" _blank ']


Summary: to take out which string to look at the string before and after it is wrapped by which two characters, use these two characters as separators to separate the string

Python shell regular expression captures complex string-specific substrings

Related Article

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.