Python IP regularization

  • 2020-04-02 09:20:42
  • OfStack

IP for regular type: r '(([12] [0-9] [0-9] | 1 - [9] [0-9] | [1-9]) \.) {3} ([12] [0-9] [0-9] | [1-9] [0-9] | [1-9])'
Here is an example
# - * - coding: utf-8 - * -
The import re
Def (IP) :
'verify IP's regular expression'
Def match_group (p) :
S = "' 211.210.209.108
Gan ffad1.210.2.108
D ffad1.210.2.109 afa "'
Com = re.com running (p)
Lst_m = com. Finditer (s)
The for m in lst_m:
Print m.g roup ()
P = r '(([12] [0-9] [0-9] | [1-9] [0-9] | [1-9]) \.) {3} ([12] [0-9] [0-9] | [1-9] [0-9] | [1-9])'
Match_group (p)
Def group () :
'' if there are multiple matches, you can use finditer to get multiple groups ''
Def match (p) :
S = 'physicist Isaac Newton, huang zhijun'
Mo = re.com running (p)
M = mo. Search (s)
If not m:
Print 'no match'
The else:
Print mo. The.findall (s)
Print 'm.g roup (0) :', m.g roup (0)
# print 'm.g roup (1) :', m.g roup (1)
# print 'm.g roup (2) :', m.g roup (2)
M_ite = mo. Finditer (s)
For ite in m_ite:
Print 'ite. Group (0)', ite. Group (0)
Print 'ite. Group (1)', ite. Group (1)
Print 'ite. Group (2)', ite. Group (2)
# p = r'(\w+) (\w+)'
P = r '(\ w +) (\ w +)'
Match (p)
If __name__ = = "__main__" :
IP ()
# group ()

Related articles: