Check whether text contains x numbers in a row [closed]

2024/9/20 17:50:38

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

Example:

da$ c0220 -> True
dsad458d69 -> False

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

Answer

The regex below checks for 10 consecutive numbers

\d{10}

In Python this becomes

if re.search(r"\d{10}", subject):# Successful match
else:# Match attempt failed
https://en.xdnf.cn/q/119466.html

Related Q&A

How to add polling interval for a GET request in python

I have a case where I have to keep checking the response of a GET call until I see the status as success in the api response. And it takes around 20 to 50 mins to get the status from active to success.…

Total beginner wrote a tic tac toe game in Python and would like some feedback

Ive decided to learn Python about 2 weeks ago, been going through various books and videos, and Ive decided to try my hand at programming a tic tac toe game. I was somewhat successful (it doesnt recogn…

Separating tag attributes as a dictionary

My entry (The variable is of string type): <a href="https://wikipedia.org/" rel="nofollow ugc">wiki</a>My expected output: { href: https://wikipedia.org/, rel: nofollow …

How can I remove duplication of 2 separate which is interrelated with each other (PYTHON)

After reading so many title, I couldnt solved the problem below. Does anyone can help me please ? For instance, I have 2 list (list_I and list_II) which is interrelated with each other. list_I = [123,…

Array within an array?

Im trying to call up an element from an array within an array in Python. For example:array = [[a1,a2,a3,a4], [b1,b2,b3,b4], [c1,c2,c3,c4]]The question is, how would I print just the value b1?

How to create a zoned of gradation area on the edge of ROI in opencv python

I have a binary image (white and black), the where Region of Interest (ROI) is black. The shape of ROI is irregular and the location of ROI can be anywhere in the frame. I want to have a smooth gradati…

Prevent Terminal resize python curses

Im writing a program on python curses and I was wondering if there is a way to block terminal resizing in order to prevent curses crashing both on Linux and Windows. This is what happens.. Can I preven…

SymPy Not Doesnt Return LaTeX

Helloo! So, Im using SymPy to make a calculation for me. The trouble is, its output should be a LaTeX expression and in make case it prints something like SymPy Calculation Output Is there any way to s…

Python Flask: How to include JavaScript file for each template per blueprint

I have read Loading external script with jinja2 template directive and Import javascript files with jinja from static folder but unfortunately no closer I have a Python Flask site which is based on htt…