检查文本是否连续包含x个数字 [英] Check whether text contains x numbers in a row

查看:71
本文介绍了检查文本是否连续包含x个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以检查给定文本是否连续包含x个数字?

Is there an option to check whether the given text contains x numbers in a row?

示例:

da$ c0220 -> True
dsad458d69 -> False

我认为我应该使用regular expressions,但我不知道如何使用.

I think I should use regular expressions but I can't figure out how.

推荐答案

下面的正则表达式检查10个连续数字

The regex below checks for 10 consecutive numbers

\d{10}

在Python中,它变为

In Python this becomes

if re.search(r"\d{10}", subject):
    # Successful match
else:
    # Match attempt failed

这篇关于检查文本是否连续包含x个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆