Python正则小实例
来源:互联网 发布:淘宝ppc和cpc的区别 编辑:程序博客网 时间:2024/06/14 10:52
def re_test(): import re s = "gsmice@sina.cn : 测试账号 : 7568 : 06286ec389c5536914d63d094f93da7a" pattern = re.compile(r"^\s*(?P<name>[^\s:]+)\s*:\s*(?P<nick>[^\s:]+)\s*:\s*(?P<passwd>[^\s:]+)\s*:\s*(?P<token>[^\s:]+)") match = pattern.search(s) if match: print(match.group('name')) print(match.group('nick')) print(match.group('passwd')) print(match.group('token'))re_test()def cofig_file_test(): import re s = '"sys_file_path" = "F:/ghost_/src/sys"' pattern = re.compile(r'^\s*"(?P<key>.+)"\s*=\s*"(?P<val>.+)"\s*\Z') # LINE_PATTERN = re.compile(r'\A\s*"(?P<key>.+?)"\s*=\s*"(?P<val>.+?)"\s*\Z') match = pattern.search(s) if match: print(match.group('key')) print(match.group('val')) # print(match)cofig_file_test()def url_regular(): import re s = "https://ww[w.goog]le.hk" # s = "URL_PATTERN = re.compile(r'https?\:\/\/[\_\.\-\?\=\/\&a-z0-9]+', re.IGNORECASE)" pattern = re.compile(r'https?:\/\/(?P<url>[_.\[\]a-z]+)')#利用反斜杠对"[","]"进行转换 match = pattern.search(s) if match: print(match.group('url'))url_regular()def re_test(): s = "select sysdate from dual where user= '@user1' and password='@password' or username='@username'" pattern = re.compile("'.*?@([a-z\d]+)'.*?'@([a-z\d]+)'.*?@([\w]+)") match = pattern.search(s) if match: print match.group(1) print(match.group(2)) print match.group(3) # print(match.group())re_test()def re_test(): s = "select sysdate from dual where user= '@user1' and password='@password' or username='@username'" pattern = re.compile("'.*?@(?P<user>([a-z\d]+))'.*?'@(?P<passwd>([a-z\d]+))'.*?@(?P<username>([\w]+))") match = pattern.search(s) if match: print(match.group(1)) print(match.group(2)) print(match.group(3)) print match.group('user') print(match.group('passwd')) print match.group('username') print(match.group())re_test()
0 0
- Python正则小实例
- python 正则 中文 实例
- Python正则表达式实例
- python 正则实例
- python爬虫小实例
- Python基础小实例
- python小实例
- [python 开发]python小实例
- python re 正则表达式实例
- Python正则表达式实例演练
- Python: 正则表达式实例透析
- Python小实例第一天
- Python小实例第一天
- Python Request库小实例
- python re 正则表达式实例2
- python类库31[正则表达式匹配实例]
- PHP、Python 相关正则函数一点实例
- Python开发——正则表达式实例
- 我的It成长之路
- uri 和url
- 第三周作业-循环与判断语句
- 写在2014-03-31
- java 类修饰符
- Python正则小实例
- ThinkPHP“学习”之路
- 进程间通信
- Windows核心编程(十)异步设备I/O
- 抓取苹果商店游戏子类
- ZOJ3720 Magnet Darts(点在多边形内)
- 【DP】Interleaving String
- javascript按钮特效--- 删除时弹出确认提示
- Eclipse下切换项目的svn地址