复习re
Posted zxy01
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了复习re相关的知识,希望对你有一定的参考价值。
#__author: "ZXYang"
#date: 2020/4/23
import re
from re import findall
# ret = re.findall(‘w..l‘, ‘hello world‘)
# print(ret)
# ^
# ret = re.findall(‘^w..l‘, ‘hello world‘)
# ret = re.findall(‘^h..l‘, ‘hello world‘)
# $
# ret = re.findall(‘w..l$‘, ‘hello world‘)
# ret = re.findall(‘w..l$‘, ‘hello worl‘)
# ret = re.findall(‘[^ab]‘, ‘absf‘)
# *
# ret = re.findall(‘ab*‘, ‘hello worldba‘)
# ret = re.findall(‘a.*x‘, ‘adfsadfasdfsdfx‘)
# +
# ret = re.findall(‘c+d‘, ‘hello bbbbccccdworlcd‘)
# print(ret)
# ? [0, 1]
# ret = re.findall(‘c?d‘, ‘hello cccdworlcdsdvvd‘)
# {}
# ret = re.findall(‘a{1,3}b‘, ‘aaaab‘)
# print(ret)
# ret = re.findall(‘a?‘, ‘abhello world‘)
# []
# ret = re.findall(‘a[c,d]e‘, ‘ade‘)
# ret = re.findall(‘[a-zA-Z0-9]‘, ‘asAD12‘)
# ret = re.findall(‘[^ab]‘, ‘absfasdfasdf‘)
# ret = re.findall(‘[^1,2]‘, ‘asfd1234‘)
#
# d
# print(re.findall(‘d{5}‘,‘fadsfa12345sf543‘))
# s
# print(re.findall(‘sad‘,‘f adsf ad12345sf543‘))
# print(re.findall(‘SadC‘,‘f adsfadC12345sf543‘))
# W
# print(re.findall(‘w‘,‘f adf a43‘))
# print(re.findall(‘wad‘,‘fad sfad43‘))
# --以什么什么特殊字符为边界(空格/逗号/特殊符号)
# print(re.findall(r‘I‘, ‘fI adI,faI$43‘))
# print(re.findall(r‘I‘, ‘fadI sI,dafI$a ‘))
# print(re.findall(r‘I‘, ‘Idfa Ifa, IFASDIF‘))
# print(re.findall(r‘BI‘, ‘fa,FASDIF‘))
# search
# print(re.search(‘sb‘, ‘sfeesbff‘))
# print(re.search(‘sb‘, ‘sbfee sbff‘))
# group
# print(re.search(‘sb‘, ‘sbfee sbff‘).group())
# print(re.search(‘sb‘, ‘absdfdaasb‘).group())
# print(re.search(‘a.‘, ‘asf‘).group())
# print(re.search(‘a+‘, ‘a+sf‘).group())
# r ==》 代表原生字符串 -------
# print(re.findall(r‘\p‘, ‘fadfp‘))
# print(re.findall(‘\\‘, ‘fadf\p‘))
# print(re.findall(r‘bl‘, ‘blow‘))
# ()+
# print(re.search(‘ab+‘, ‘assababbb‘).group())
# print(re.search(‘(ab)‘, ‘assabab‘).group())
# print(re.search(‘(ab)+‘, ‘assabab‘).group())
# |
# print(re.search(‘(as)|2‘, ‘as‘).group())
# print(re.search(‘as|2‘, ‘2assabab‘).group())
# match()
# print(re.match(‘aa‘, ‘sdfaa‘))
# print(re.match(‘aa‘, ‘aasdfaa‘).group())
# split
# print(re.split(‘[js]‘, ‘ajdsbf‘))
# sub subn(可查看替换次数)
# print(re.subn(‘z..y‘, ‘aaa‘, ‘dafafsbzxsyfzxxyd‘, 2))
# print(re.sub(‘a..m‘,‘zxyang‘, ‘fafaaaxxmaa‘))
# compile
# obj = re.compile(‘.com‘)
# print(obj.split(‘fasdf.comcc‘))
# print(obj.findall(‘fasdfasd.comddd‘))
# 练习
# print(re.search(‘(?P<name>d{3})‘, ‘adf123fd55‘).group())
# obj = re.compile(‘d{3}‘)
# ret = obj.search(‘ads123‘).group()
# print(ret)
# a = re.finditer(‘d‘, ‘faaa123fd‘)
# print(next(a))
# print(next(a))
# print(next(a).group())
# ?: 可以取消优先级
# print(re.findall(‘www.(?:w+).com‘, ‘www.baidu.com‘))
# * [o, +oo] + [1, +oo] ?[0,1]
# {0,+} {1,+oo} {0,1}
# ?P
# print(re.search(‘(?P<id>d{3})/(?P<name>w{3})‘, ‘saaa123/kkkaa‘).group())
# print(re.search(‘(?P<id>d{3})/(?P<name>w{4})‘, ‘112233/aabbcc‘).group())
# 总结:
# findall():将所有结果返回到一个列表
# search():返回到的第一个对象,group()方法可以返回结果
# match():只在字符串开始位置匹配,也返回匹配到第一个对象
以上是关于复习re的主要内容,如果未能解决你的问题,请参考以下文章
复习BUUCTF:[网鼎杯2018]Unfinish --- python爬虫 + re sql注入,substr二次注入,hex二次注入 不用bool注入点的substr