python - 不明白为什么简单的正则表达式不匹配
问题描述
我期望以下模式:
pattern1=r"\Ar(evolution)?ide\bthe\b(earth)\Z"
匹配:
string=r"ride the earth"
相反,以下模式匹配:
pattern2=r"r"\Ar(evolution)?ide \bthe\b (earth)\Z"
和\b
空白一样,为什么模式 1 不匹配字符串?
解决方案
\b
不是空间;它匹配单词开头或结尾的空字符串。
\s
是一个空白字符,所以会匹配。r"\Ar(evolution)?ide\sthe\s(earth)\Z"
推荐阅读
- macos - 用于在浏览器中打开文件的 Shell 脚本未按预期工作
- css - 使用物化 css 的图像网格/画廊
- php - Laravel 5.6 - 如何从非关系表中获取发布数据?
- android - 在 logcat 中从 Sqlite android 检索数据
- delphi - TWebRequest 中的标头 HTTP 来源
- node.js - 在数据事件上将额外参数传递给 fs.createReadStream
- stringtokenizer - 使用 Adasyn() 或 SMOTE() 错误:无法将字符串转换为浮点数
- sql-server - SQL - 更新表中的主键
- c# - 验证某个图像是否存在
- windows - 显卡有单独的ID,可以区分单个设备吗?