Python正则表达

import re
pattern = re.compile('hello')
match = pattern.match("hello world")
print (match)


word = "http://www.ichunqiu.com/1.1.1" 

print(re.findall('.',word))      # . 是匹配除/n以外的字符
print(re.findall('\.',word))     # \ 是匹配需要转义的字符
print(re.findall('[^\.:\/\/]',word))# [] 对应位置可以是任意字符 如[^abc]表示不是abc的字符
print(re.findall('\d.',word))     # \d 匹配数字
print(re.findall('\D',word))     # \D 匹配非数字
print(re.findall('\s',word))     # \s 匹配空格
print(re.findall('\S',word))     # \S 匹配非空字符
print(re.findall('\w',word))     # \w 匹配单词字符
print(re.findall('\W',word))     # \W 匹配非单词字符 如 :、/、。
print(re.findall('http*',word))     # * 匹配前1个字符0次或者无数次,+ 1次或者无限次 ?0次或者一次
print(re.findall('http{2}','httphttp')) # {m}匹配前一个字符m次,{m,n}匹配到n-m次
print(re.findall('abc|fgh','abcfgh'))  # | 先匹配|左边,没有就匹配右边
print(re.findall('http://(.*?)/1.1.1',word)) # ()将()作为一个分组,从表达式的左边开始遇到(就+1

运行结果:

 

 

posted @ 2020-02-24 15:55  信安专业小白  阅读(134)  评论(0)    收藏  举报