1. Import the corresponding package for the regular expression:
1 ImportRe2 Re.search (pattern,string)3 Example:4Re.search ("[0123456789]","2")!=none#true to indicate a successful match. 5Re.search ("^[0123456789]$"," A")!=none#false to indicate that the match failed.
2. Ordinary characters:
-Denotes range, [0-9],[a-z] and so on.
3. Metacharacters and Escapes:
Metacharacters: [,],^,$,-these are meta characters. If you need to convert a meta character to a normal character, you need to escape = plus a backslash character \
1 #as ordinary characters2Re.search ("^[-09]$","3")!=none#False3Re.search ("^[-09]$","-")!=none#True4 5 #as a meta-character6Re.search ("^[0-9]$","3")!=none#True7Re.search ("^[0-9]$","-")!=none#False8 9 #after escaping as normal charactersTenRe.search ("^[0\\-9]$","3")!=none#False OneRe.search ("^[0\\-9]$","-")!=none#True
Python Regular Expressions