Python Regular expression----RE module

Source: Internet
Author: User

1. Regular expressions

A regular is a way to describe a string or character by combining symbols with special meanings.

2. Common regular matching patterns

Import re
Print(Re.findall ('\w','Hello_ | Egon 123'))#Match alphanumeric underlinePrint(Re.findall ('\w','Hello_ | Egon 123'))#match with small w non-numeric character underlinePrint(Re.findall ('\s','Hello_ | Egon 123 \ t'))#match any blank character such as [\t,\n,\r,\f]Print(Re.findall ('\s','Hello_ | Egon 123 \ t'))#match with small s to any of the whitespace characters in the opposite directionPrint(Re.findall ('\d','Hello_ | Egon 123 \ t'))#match any numberPrint(Re.findall ('\d','Hello_ | Egon 123 \ t'))#match any non-numericPrint(Re.findall ('h','hello_ | Hello h egon 123 \ t'))#Match characterPrint(Re.findall ('\ahe','hello_ | Hello h egon 123 \ t'))#match the beginning of the string with the ^Print(Re.findall ('^he','hello_ | Hello h egon 123 \ t'))## Print (Re.findall (' 123\z ', ' hello_ | Hello h egon 123 \ n \t123 ')) #匹配字符串的结尾, there is a newline, which matches only the end string before the line break. Print(Re.findall ('123\z','hello_ | Hello h egon 123 \ \t123'))#match string ends equal to $Print(Re.findall ('123$','hello_ | Hello h egon 123 \ \t123'))Print(Re.findall ('\ n','hello_ | Hello h egon 123 \ \t123'))#match a line breakPrint(Re.findall ('\ t','hello_ | Hello h egon 123 \ \t123'))#Match a tab

Python Regular expression----RE module

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.