Python Regular Expression

Source: Internet
Author: User

The Python Regular Expression module is re.

Common steps to use a regular expression:

1. First Use Re. Compile to compile a regexobject to indicate a Regexp
2. Use the match and search methods of pattern to obtain the matchobject.
3. Use matchobject to obtain the matching position, matched string, and other information.

Common regexobject functions:

Reobj. Match (STR [, POS [, endpos]) if the start of STR matches reobj, A matchobject is returned; otherwise, none is returned.
Reobj. Search (STR [, POS [, endpos]) Searches str for the first part that matches reobj.
Reobj. findall (STR) searches for all matching parts in STR and returns a tuple, which is a matched string.

Matchobject common functions:

M. Start () returns the start position. For reobj. Match (), start () always returns 0
M. End () returns the end position (excluding the characters of this position)
M. span () returns a tuple representation (M. Start (), M. End ())
M. pos (), M. endpos (), M. Re (), and M. String () indicate the parameters in the matchobject function.
M. finditer () returns an iterator to traverse all the matchobjects found.
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.