Python IP Regular type _python

Source: Internet
Author: User
IP regular is: R ' ([12][0-9][0-9]|[ 1-9][0-9]| [1-9]) \.) {3,3} ([12][0-9][0-9]| [1-9] [0-9]| [1-9]) '
The following is an example
#-*-Coding:utf-8-*-
Import re
def IP ():
' Validate IP's regular '
def match_group (P):
s = ' ' 211.210.209.108
Gan ffad1.210.2.108
D Ffad1.210.2.109afa ' '
com = Re.compile (p)
Lst_m = Com.finditer (s)
For M in Lst_m:
Print M.group ()
p = R ' ([12][0-9][0-9]|[ 1-9][0-9]| [1-9]) \.) {3,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 more than one group."
def match (P):
s = ' Isaac Newton, physicist, Huang Zhijun '
Mo = Re.compile (p)
m = Mo.search (s)
If not m:
print ' no match '
Else
Print Mo.findall (s)
print ' M.group (0): ', M.group (0)
# print ' M.group (1): ', M.group (1)
# print ' M.group (2): ', M.group (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 ()

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.