Regular Ex Notes

Source: Internet
Author: User

Https://docs.python.org/2/howto/regex.html

Identifiers:

\d any number

\d anything but a number

\s Space

\s anything but a space

\w any character

\w anything but a character

. Any character, except for a newline

\b The whitespace around words

\. A period

Modifiers:

{1,3} we ' re expecting 1-3

+ Match 1 or more

? Match 0 or 1

* Match 0 or more

$ match the end of a string

^ Matching the beginning of a string

| Either or

[] Range or "variance" [a-za-z1-5]

{x} expecting "X" Amount

White Space characters:

\ n New Line

\s Space

\ t tab

\e Escape

\f Form Feed

\ r return

DONT forget!:

. + * ? { } $ ^ ( ) { } | \

Need to escape them

Method/attribute Purpose
Match () Determine if the RE matches at the beginning of the string.
Search () Scan through a string, looking for all location where this RE matches.
FindAll () Find all substrings where the RE matches, and returns them as a list.
Finditer () Find all substrings where the RE matches, and returns them as aniterator.

Method/attribute Purpose
group () return the string matched by the re
start () end () span () return a tuple containing the (start, End) positions of the match

Regular Ex Notes

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.