python里使用正则表达式的ASCII模式
2023-09-14 09:10:36 时间
目前,基本上都使用python3来开发了,但是有时为了兼容旧的python2的代码,在正则表达式里主要是字符串的表示方式不同了,在python3里是使用Unicode来表示字符串和正则表达式,而在python2里是使用ASCII来表示的,所以在python3里怎么样设置才兼容旧的方式呢?其实可以通过ASCII的标志来解决,如下面的例子:
结果输出如下:
Text : Français złoty Österreich
Pattern : \w+
ASCII : ['Fran', 'ais', 'z', 'oty', 'sterreich']
深入浅出Numpy
五子棋游戏开发
http://edu.csdn.net/course/detail/5487
#python 3.6
#蔡军生
#http://blog.csdn.net/caimouse/article/details/51749579
#
import re
text = u'Français złoty Österreich'
pattern = r'\w+'
ascii_pattern = re.compile(pattern, re.ASCII)
unicode_pattern = re.compile(pattern)
print('Text :', text)
print('Pattern :', pattern)
print('ASCII :', list(ascii_pattern.findall(text)))
print('Unicode :', list(unicode_pattern.findall(text)))
结果输出如下:
Text : Français złoty Österreich
Pattern : \w+
ASCII : ['Fran', 'ais', 'z', 'oty', 'sterreich']
Unicode : ['Français', 'złoty', 'Österreich']
深入浅出Numpy
http://edu.csdn.net/course/detail/6149
Python游戏开发入门
你也能动手修改C编译器
纸牌游戏开发
http://edu.csdn.net/course/detail/5538
五子棋游戏开发
http://edu.csdn.net/course/detail/5487
RPG游戏从入门到精通
http://edu.csdn.net/course/detail/5246
WiX安装工具的使用
http://edu.csdn.net/course/detail/5207
俄罗斯方块游戏开发
http://edu.csdn.net/course/detail/5110
boost库入门基础
http://edu.csdn.net/course/detail/5029
Arduino入门基础
http://edu.csdn.net/course/detail/4931
Unity5.x游戏基础入门
http://edu.csdn.net/course/detail/4810
TensorFlow API攻略
http://edu.csdn.net/course/detail/4495
TensorFlow入门基本教程
http://edu.csdn.net/course/detail/4369
C++标准模板库从入门到精通
http://edu.csdn.net/course/detail/3324
跟老菜鸟学C++
http://edu.csdn.net/course/detail/2901
跟老菜鸟学python
http://edu.csdn.net/course/detail/2592
在VC2015里学会使用tinyxml库
http://edu.csdn.net/course/detail/2590
在Windows下SVN的版本管理与实战
http://edu.csdn.net/course/detail/2579
Visual Studio 2015开发C++程序的基本使用
http://edu.csdn.net/course/detail/2570
在VC2015里使用protobuf协议
http://edu.csdn.net/course/detail/2582
在VC2015里学会使用MySQL数据库
http://edu.csdn.net/course/detail/2672
相关文章
- Python爬虫之正则表达式的使用(三)
- 使用python读取word文件里的表格信息
- Python正则表达式如何进行字符串替换实例
- [Python] Create a minimal website in Python using the Flask Microframework
- 【python cookbook】【字符串与文本】7.定义实现最短匹配的正则表达式
- Python正则表达式如何进行字符串替换实例
- paip.文件读写api php java python总结.txt
- 粒子群算法(带约束处理)——Python&Matlab实现
- 有了这个 Python 库,以后再也不用写正则表达式了
- Python实现基于物品的协同过滤推荐算法构建电影推荐系统
- Python Flask框架学习29:项目管理器Manager/传递参数/优化项目代码结构
- python gz解压
- 【Python练习】正则表达式
- Python、PHP:手机号匹配正则表达式
- python 正则表达式
- Python: 正则表达式匹配反斜杠 ""
- python里使用正则表达式搜索单词
- python里预先编译正则表达式提高效率
- python里为什么需要使用装饰器(decorator)
- python里使用正则表达式来替换匹配成功的组名
- python里使用正则表达式的重复模式
- python里使用正则表达式的DOTALL标志
- python里使用正则表达式的全匹配功能
- python(一):multiprocessing——死锁
- 【python中级】 多进程之间通过Queue队列(先进先出)传输数据