Python basic re module

Source: Internet
Author: User

In essence, a regular expression (or RE) is a small, highly specialized programming language (in Python) that is embedded in Python and implemented through the RE module. The regular expression pattern is compiled into a sequence of bytecode, which is then executed by a matching engine written in C.

Character match (normal character, metacharacters):

1 Ordinary characters: Most characters and letters will match themselves
>>> Re.findall (' Alvin ', ' Yuanalesxalexwupeiqi ')
[' Alvin ']

2 meta characters:. ^ $ * + ? { } [ ] | () \ #共11个元字符

def findall (pattern, string, flags=0):    "" "Return A list of all non-overlapping Matches in the string.    If one or more capturing groups is present in the pattern, return    a list of groups; This would be a list of tuples if The pattern has more    than one group.    Empty matches is included in the result. """    return _compile (pattern, flags). FindAll (String)
FindAll Sword Spectrum

Re.findall (pattern,string) #找到所有的匹配元素, return to list

(1). : matches any symbol except \ n
Print (Re.findall ("A.+d", "ABCD"))

Python basic 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.