python - Python re:3个字母和逗号后的模式的正则表达式
问题描述
如何在python re中编写正则表达式,其中模式是:3个英文字母后跟一个逗号
例子:
string_var = "AAA, BBB, CCC" # follows the pattern
string_var = "AAA, BBBB, CCC, DDD" # does not follow the pattern
解决方案
如果您只想检查字符串是否匹配,请使用^[A-Za-z]{3}, [A-Za-z]{3}, [A-Za-z]{3}$
( https://regexr.com/5i22s )。这对于“AAA, BBB, CCC”是正确的,但对于像“test asf, cat, dog”这样的查找匹配没有用。
^ Start of string
[A-Za-z] Alphabet characters
{3} 3 alphabet characters
, A comma followed by a space
...
$ End of string
推荐阅读
- apache-camel - 如何关联 Camel ExchangeCompletedEvent 和多播/拆分?
- php - 如何将翻译放入 Laravel 表单中的数组中?
- swift - Swift:动画 uilayoutconstraints 和更改 alpha 会导致崩溃
- timezone - ISO8601 与时区和时间跨度
- export-to-csv - 从 Grafana 图表导出 CSV 中的数字格式错误
- python - 获取 KeyError:Adj。在 python 中关闭
- javascript - React - 在组件之间传递方法引用
- java - CXF 总线 - 添加具有自定义超时的 HttpConduitFeature
- node.js - 如何在 Windows 中将 npm start 添加为服务
- json - 打字稿中的 JSON 转换