Python regex note

Source: Internet
Author: User
Tags character classes


To remember Python regex easily, we organise Python regex notes from concrete to abstract, and from simple to sophisticate D.

I, Important character:

1, quantitive character:

? : [0,1], *:[0,INFI), +:(0,infi), {N}:[n rep], {m,}:[m, infi), {, n}:[0,n], {m,n}:[m,n],

? (nogreedy option)

2, Begin and End:

^: Beginning, $: ending

3, Making own character class:

[ABC], [^ABC]: ^ Rep non
4, Character classes:

\d,\d,\s,\s,\w,\w
5:dot (or wildcard) character:

. ,   .*,  (.*) ? : Rep Nongreedy Fashion

II, usefull regex arguments

1, Re. Dotall:match all characters, including the newline character.

2, Re. I (re. IGNORECASE): Ignore uppercase

3, Re. Verbose:spread the regex over multiple lines with comments.

4, | : We could use pipe character to cobine all three above arguments.

III, generate Regex procedure:

1, regex = Re.compile (r "")

2.1.1, Regex.search ("")

2.1.2, Regex.search (""). Group (), (or Regex.search (""). Group (No)), greedy Defalut

2.2, Regex.findall ("")

2.3 Regex.sub ("")

3, Re.compile (r "" (

          

) ", Re. VERBOSE): To manage more complex regrexes.


6:re. Dotall, Re. I

Python regex note

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.