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