Python: Regular expression matches backslash "\"

Source: Internet
Author: User

Python Regular expression matches backslash "\"

eg

>>>a= ' w\w\w '

' w\\w\\w ' # printed "\ \" is escaped to a backslash "\"

If you need to match string A, you need to match a backslash "\"

>>>re.split (r ' \ \ \ ', a)

[' W ', ' W ', ' W ',]

Escaping the string first and then escaping the regular expression

Because all the characters in the original string are used directly in literal sense, do not escape the special characters, so do not escape the string, directly into the second ' regular escape ', in the regular escape "\ \" is escaped to "\", indicating that the type needs to match a backslash

If there is inappropriate place, also hope to contain and point out, thanks.

Reference from http://blog.csdn.net/jinixin/article/details/56705284

Python: Regular expression matches backslash "\"

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.