我是靠谱客的博主 直率小懒猪,最近开发中收集的这篇文章主要介绍python语法正则表达式_Python篇----正则表达式语法(基础),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#-*-coding:utf8-*-

#导入re库文件

import re

# from re import findall,search,S

secret_code = 'hadkfalifexxIxxfasdjifja134xxlovexx23345sdfxxyouxx8dfse'

#.的使用举例

# a = 'xy123'

# b = re.findall('x...',a)

# print b

#*的使用举例

# a = 'xyxy123'

# b = re.findall('x*',a)

# print b

#?的使用举例

# a = 'xy123'

# b = re.findall('x?',a)

# print b

'''上面的内容全部都是只需要了解即可,需要掌握的只有下面这一种组合方式(.*?)'''

# #.*的使用举例

# b = re.findall('xx.*xx',secret_code)

# print b

# # #.*?的使用举例

# c = re.findall('xx.*?xx',secret_code)

# print c

#

#

#

# #使用括号与不使用括号的差别

# d = re.findall('xx(.*?)xx',secret_code)

# print d

# for each in d:

# print each

# s = '''sdfxxhello

# xxfsdfxxworldxxasdf'''

#

# d = re.findall('xx(.*?)xx',s,re.S)

# print d

#对比findall与search的区别

# s2 = 'asdfxxIxx123xxlovexxdfd'

# # f = re.search('xx(.*?)xx123xx(.*?)xx',s2).group(2)

# # print f

# f2 = re.findall('xx(.*?)xx123xx(.*?)xx',s2)

# print f2[0][1]

#sub的使用举例

# s = '123rrrrr123'

# output = re.sub('123(.*?)123','123%d123'%789,s)

# print output

#演示不同的导入方法

# info = findall('xx(.*?)xx',secret_code,S)

# for each in info:

# print each

#不要使用compile

# pattern = 'xx(.*?)xx'

# new_pattern = re.compile(pattern,re.S)

# output = re.findall(new_pattern,secret_code)

# print output

#匹配数字

a = 'asdfasf1234567fasd555fas'

b = re.findall('(d+)',a)

print b

最后

以上就是直率小懒猪为你收集整理的python语法正则表达式_Python篇----正则表达式语法(基础)的全部内容,希望文章能够帮你解决python语法正则表达式_Python篇----正则表达式语法(基础)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(62)

评论列表共有 0 条评论

立即
投稿
返回
顶部