Python:正则表达式中的POSIX字符类?

编程入门 行业动态 更新时间:2024-10-28 03:28:35
本文介绍了Python:正则表达式中的POSIX字符类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在Python中给定的字符串中搜索10个isprint字符的序列?

How can I search for, say, a sequence of 10 isprint characters in a given string in Python?

使用GNU grep,我只需执行grep [[:print:]]{10}

With GNU grep, I would simply do grep [[:print:]]{10}

推荐答案

由于Python re模块不支持POSIX,因此必须在字符类的帮助下对其进行仿真.

Since POSIX is not supported by Python re module, you have to emulate it with the help of character class.

您可以使用 regular-expressions.info 中的一个并添加限制量词{10}:

You can use the one from the regular-expressions.info and add a limiting quantifier {10}:

[\x20-\x7E]{10}

请参见演示

或者,您可以使用 Matthew Barnett regex模块,该模块声称支持POSIX字符类(支持POSIX字符类.).

Alternatively, you can use Matthew Barnett regex module that claims to support POSIX character classes (POSIX character classes are supported.).

更多推荐

Python:正则表达式中的POSIX字符类?

本文发布于:2023-10-09 02:08:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1474407.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   正则表达式   Python   POSIX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!