Python Learning note 013_ Regular expressions

Source: Internet
Author: User

The regular expressions in Python are implemented through the RE module.

a wildcard character. Represents any character other than line break;

Use R ' re ' when writing regular expressions, R + Regular expression content

Import re>>> >>> re.search (R'Fish. ','I love fishc.com! ' )<_sre. Sre_match object; Span= (7, a), match='fishc'#  If you want to match.  use  \.

\d represents a numeric character

>>> Re.search (R'\d','I love fishc.com 123! ' )<_sre. Sre_match object; Span= (+), match='1>>>>

[] match to any one of the characters in the brackets, and the match is successful.

>>> Re.search (R'[aeiou]','I love fishc.com! ' )<_sre. Sre_match object; Span= (3, 4), match='o'

[] can be used-Indicates the range

>>> Re.search (R'[A-z]','I love fishc.com! ' )<_sre. Sre_match object; Span= (2, 3), match='l'

{m,n} matched number of intervals

>>> Re.search (R'ab{2,3}c','aabbccddacc') <_sre. Sre_match object; Span= (1, 5), match='abbc'

Matching IP

# match IP, from practice can be seen several or together, the first match on no longer match the second >>> >>> >>> re.search (R'(25[ 0-5]|2[0-4]\d|1\d{2}| [1-9]\d|\d] \.) {3} (25[0-5]|2[0-4]\d|1\d{2}| [1-9]\d|\d]','192.168.1.12')<_sre. Sre_match object; span= (0, a), match='192.168.1.12'

Small Turtle Python3 Regular expression Official document translation explanation address

Python3 how to gracefully use regular expressions (detail one) http://bbs.fishc.com/thread-57073-1-1.html

Python3 how to gracefully use regular expressions (Detailed II) http://bbs.fishc.com/thread-57188-1-1.html

Python3 how to gracefully use regular expressions (detailed three) http://bbs.fishc.com/thread-57207-1-1.html

Python3 how to gracefully use regular expressions (detailed four) http://bbs.fishc.com/thread-57271-1-1.html

Python3 how to gracefully use regular expressions (detailed five) http://bbs.fishc.com/thread-57317-1-1.html

Python3 how to gracefully use regular expressions (detailed six) http://bbs.fishc.com/thread-57362-1-1.html

Python3 how to gracefully use regular expressions (detailed seven) http://bbs.fishc.com/thread-57438-1-1.html

Python3 Regular Expressions special symbols and their usage (detailed list) http://bbs.fishc.com/thread-57691-1-1.html




Python Learning note 013_ Regular expressions

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.