Python Regular Expression

Source: Internet
Author: User

(|): Matches multiple regular expression modes. At | home matches at and home

(.): Match any single character. F. o matches any character between f and o, such as foo, f # o

(^/$/\ B/\ B): ^ matches the string starting from the start, $ or \ Z matches the end of the string, and \ B indicates the boundary of the word, \ B indicates that it is not the boundary of a word, for example, a string starting with "From", a string ending with "hi", ^ Subject: hi $ matches a string consisting of only Subject: hi, \ bthe matches a string starting with the, \ bthe \ B matches only the, \ Bthe matches a string that contains the but does not start with.

([]): Character class, B [aeiou] t matching bat, bet, bit, bot,

(-): The specified range is [0-9]. The value ranges from 0 to 9.

(^): No: [^ aeiou] matches non-Vowel characters

(*, + ,?, {}): Multiple occurrences/repeated matches

Special Character and Character Set: \ d represents a decimal number, \ w represents the character set of the entire character number (A-Za-z0-9), \ s represents a blank character, uppercase character represents mismatch, \ D indicates a non-decimal number

Common functions:

Re. match (pattern, string, flags = 0): Start from the first character for pattern matching.

Re. search (pattern, string, flags = 0): search mode from left to right.

Re. findall (partten, string): Find the matching part for each occurrence.

Re. sub (partten, str, string): Find the matching string in the string, change it to str, and return.

Re. split (partten, string): Find the string that matches the pattern, and split the string by its.

Note:

(): Group partten to make it easy to retrieve (group/groups) after matching ).

 

 

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.