查看“Python正则表达式1”的源代码
←
Python正则表达式1
跳转至:
导航
,
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
[[文件:python10-20.png]] <nowiki>import re line = "bobby123" #以b开头,重复任意多个字符 regex_str = "^b.*" if re.match(regex_str,line): print("yes") #以3结尾 regex_str2 ="3$" if re.match(regex_str,line): print("yes") #从右侧向左,贪婪匹配 line2 ="boooooobby123" regex_str = ".*(b.*b).*" match_obj = re.match(regex_str,line2) if match_obj: print(match_obj.group(1)) #从左边开始,非贪婪匹配 line3 ="boooooobby123" regex_str = ".*?(b.*?b).*" match_obj = re.match(regex_str,line3) if match_obj: print(match_obj.group(1)) </nowiki>
返回至
Python正则表达式1
。
导航菜单
个人工具
登录
命名空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
帮助
工具
链入页面
相关更改
特殊页面
页面信息