python - Python re模块,单词出现的长度
问题描述
我有正则表达式
m=re.search('z+',"i want to zzz zzzzzzz this is end")
如何找到忽略空格10(3z + 7z)的连续z的长度
"example str want to zz z this is end" ->3(2+1)
我是新来的,如有遗漏请评论
解决方案
您将需要使用稍微不同的正则表达式,例如z[z ]*
返回一串 z 和空格,然后用于s.count()
计算有多少 z:
matches = re.findall("z[z ]*", "i want to zzz zzzzzz this is end")
result = [s.count('z') for s in matches]
print( result )
输出:
[9]
推荐阅读
- android - 使用改造 android 裁剪后图像未上传
- java - Java - 使用 POI 过滤 Excel 文件的行
- javascript - 在 JavaScript 中转换对象
- python-3.x - 在 python 中使用 ggplot 的 Power BI
- android - 在按钮单击时使用不同的数据不断更新相同的活动
- r - 用DF中的标签替换数字
- javascript - 通过ajax传递给PHP时如何为每个数组元素添加单引号?
- sql-server - PowerShell & SQL Server:尝试为 ManagedComputer 检索对象的数据失败
- sql - 在 oracle SQL developer 1.5.5 中使用模式浏览器打开对象时 SQL 脚本损坏
- flutter - 未找到用于签署配置“发布”的密钥库文件。- 颤动