#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
#
# a = re.match(r"\d{11}", "13537652617") # 匹配手机号码
# print(a.group())
#
# b = re.match(r"\d{3,4}-?\d{7,8}", "010-12345678")
#
# if b != None:
# print(b.group())
#
# html_s = """
# adfasfas
# fdasf
# afdas
# asdfasffasf
# """
#
# c = re.match(r".*", html_s, re.S)
# print(c.group())
#
# d = re.match(r"^[a-zA-Z_][a-zA-Z0-9]*$", "name1")
# print(d.group())
e = re.match(r"[0-9a-zA-Z_]{1,15}@(163|126)\.com$", "dasf@126.com")
print(e.group()) # 正常匹配
print(e.group(1))# 想取哪个值就括起来按序号取出
#
# f = re.match(r"([0-9a-zA-Z_]{1,15})@(163|126)\.com$", "dasf@126.com")
# print(f.group(1)) # 取第一个括号
#
#
# html_ss = "<tatil><h1>admin</h1></tatil>"
# g = re.match(r"<(\w*)><(\w*)>.*</\2></\1>", html_ss)
# print(g.group()) # 标签一样的可以用1、2、3.。。来指定前面一样的
#
# strs = "GET /index.html HTTP1.1"
# h = re.match(r"[^/]+(/[^ ]*)", strs)
# print(h.group(1))
python正则小记
最新推荐文章于 2023-05-05 23:53:49 发布