python匹配问题
来源:互联网 发布:phpstudy如何配置域名 编辑:程序博客网 时间:2024/06/10 06:43
print('%s' % 42) #输出字符串类型print('%d' % 42) #十进制整数print('%d%%' % 100) #文本值本身actor = 'richard gere'cat = 'chester'weight = 28print("my wife's favorite actor is %s" % actor) #字符串类的%s意味着需要插入一个字符串,字符串中出现%的次数需要与%之后所提供的 #整数项个数相同print("our cat %s weighs %s pounds" % (cat,weight)) #如果需要插入多个数据,则需要将它们封装在一个元组当中#使用match()进行准确匹配:只能检测以模式串作为开头的源字符串import resource = 'young frankenstein'm = re.match('you',source) #从源字符串的开头开始匹配if m: #匹配成功返回了对象,将它输出看看匹配得到的到底是什么 print(m.group())import resource = 'young frankenstein'm = re.search('frank',source) #search()可以检测任何位置的匹配if m: print(m.group())m = re.match('.*frank',source)if m : #match返回对象 print(m.group())# .代表任何单一字符# *代表任意一个它之前的字符, .*代表任意多个字符(包括0个)# frank是我们想要在源字符串中某处进行匹配的短语#使用search()寻找首次匹配m = re.search('frank',source)if m: #search返回对象 print(m.group)#使用fidall()寻找所有匹配m = re.findall('n',source)print(m)print('found',len(m),'source')m = re.findall('.n',source) #n前加上一个.匹配时加上前面的一个字母,n后面加上一个. 则匹配时后面加上一个字母print(m)print('found',len(m),'source')#使用split()按匹配切分m = re.split('n',source)print(m) #split返回的列表import stringprintable = string.printableprint(len(printable))print(printable[50:])print(re.findall('\d',printable)) #哪些字符是数字print(re.findall('\w',printable)) #哪些是数字,字符,下划线print(re.findall('\s',printable)) #哪些是空格符source = '''I wish I may, I wish I might have a dish of fish tonight'''print(re.findall('wish',source))print(re.findall('wish|fish',source))print(re.findall('^wish',source))print(re.findall('^I wish',source))print(re.findall('fish $',source))print(re.findall('fish tonight.$',source))
阅读全文
0 0
- python中文匹配问题
- python匹配问题
- Python中的正则表达式匹配中文问题
- Python字符串匹配存在的问题
- python求解括号匹配的相关问题
- Python中正则表达式对中文的匹配问题
- python执行数据库查询时类型不匹配的问题
- Python中正则表达式对中文的匹配问题
- Python中正则表达式对中文的匹配问题
- Python读取JSON数据,并解决字符集不匹配问题
- python读取JSON数据,并解决字符集不匹配问题
- python/正则匹配使用中遇到的问题
- python 常用正则匹配
- Python的模式匹配
- python 匹配关键字
- python 查找匹配
- python匹配中文
- python 常用正则匹配
- jQuery<5.1>
- 你不得不知道的5道海量数据题
- Jedis分布式+序列化
- node(使用events模块)
- LeetCode hard 335. Self Crossing
- python匹配问题
- 二叉树
- 传输层简介
- 响应式图片的设计
- Ubuntu上搭建mysql服务器及外部访问
- JustOj1264: 顺序查找
- 全国计算机等级考试三级网络技术考试大纲
- 112. Path Sum
- 我的模块化代码