标签:exp static ssi files advance request ram 行高 断言
正则表达式:Regular Expression,是一些由特殊的字符和符号组成的字符串,主要用来进行高级的文本匹配、搜索、替换等功能操作。
正则表达式是一个独立的技术,python中提供了re模块来支持正则表达式
import re
target = "hello, email@qq.com regexp in python with regular on expression"
reg = r"l"
print(re.findall(reg, target))
"""
FILE : 正则表达式语法操作
DATETIME: 2018/10/18 11:22
AUTHOR : chenliang
DESC :
"""
import re
s = ‘‘‘Are you new to Django or to programming? This is the place to start!
From scratch: Overview | Installation
Tutorial: Part 1: Requests and responses | Part 2: Models and the admin site
| Part 3:
Views and templates | Part 4: Forms and generic views | Part 5: Testing |
Part 6:
Static files | Part 7: Customizing the admin site
Advanced Tutorials: How to write reusable apps | Writing your first patch
for Django123_
‘‘‘
# 1 基本语法
reg1 = r"to"
print(re.findall(reg1, s))
# [‘to‘, ‘to‘, ‘to‘, ‘to‘, ‘to‘, ‘to‘, ‘to‘]
# 2 或者匹配
reg2 = r"Django|part"
print(re.findall(reg2, s))
# [‘Django‘, ‘Django‘]
# 3 开头匹配
reg3 = r"^Are"
print(re.findall(reg3, s))
# [‘Are‘]
# 4 结尾匹配
reg4 = r"Django123_$"
print(re.findall(reg4, s))
# [‘Django123_‘]
# 5 认识字符匹配
reg5 = r"Ho."
print(re.findall(reg5, s))
# [‘How‘]
# 6 范围匹配?
reg6 = r"pr?"
print(re.findall(reg6, s))
# [‘pr‘, ‘p‘, ‘p‘, ‘p‘, ‘p‘, ‘p‘, ‘p‘]
# 7 范围匹配+
reg7 = r"pr+"
print(re.findall(reg7, s))
# [‘pr‘]
# 8 范围匹配*
reg8 = r"pr*"
print(re.findall(reg8, s))
# [‘pr‘, ‘p‘, ‘p‘, ‘p‘, ‘p‘, ‘p‘, ‘p‘]
# 9 范围匹配{m}
reg9 = r"l{2}"
print(re.findall(reg9, s))
# [‘ll‘]
# 10 范围匹配{m, n}
reg10 = r"l{1,3}"
print(re.findall(reg10, s))
# [‘l‘, ‘ll‘, ‘l‘, ‘l‘, ‘l‘, ‘l‘, ‘l‘, ‘l‘]
# 11 范围匹配{0-9}
reg11 = r"[0-9]+"
print(re.findall(reg11, s))
# [‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘, ‘7‘, ‘123‘]
# 12 范围匹配[a-z]
reg12 = r"[a-z]{10}"
print(re.findall(reg12, s))
# [‘programmin‘, ‘nstallatio‘, ‘ustomizing‘]
# 13 范围匹配[a-zA-Z0-9_]
reg13 = r"[a-zA-Z0-9_]{10}"
print(re.findall(reg13, s))
# [‘programmin‘, ‘Installati‘, ‘Customizin‘, ‘Django123_‘]
标签:exp static ssi files advance request ram 行高 断言
原文地址:https://www.cnblogs.com/chenliang0309/p/9815464.html