Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8252447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:34:09+00:00 2026-06-08T00:34:09+00:00

I am trying to find a range of numbers within a string. The different

  • 0

I am trying to find a range of numbers within a string. The different ranges are listed below. How can I search a specific range of number?

Ensure the first number is between [1, 17], the second between [1, 37], etc.

import re   
Test1 = "This is a test 5-9-81-15"

A1 = range(1, 17)
A2 = range(1, 37)
A3 = range(76, 89)
A4 = range(13, 27)

x = re.search("{0}-{1}-{2}-{3}".format(A1, A2, A3, A4), Test1) 

if x: 
    print ("Match")
else:
    print ("No Match")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:34:10+00:00Added an answer on June 8, 2026 at 12:34 am

    If you can get a string of just the numbers, here is how you might check to see if it fits your requirement:

    >>> s = "5-9-81-15"          # String to parse
    >>> lb = [1, 1, 76, 13]      # List of lower bounds
    >>> ub = [17, 37, 89, 27]    # List of upper bounds
    
    >>> vals = [int(x) for x in s.split('-')]   # vals contains [5, 9, 81, 15]
    
    >>> all(x > L and x < U for x, L, U in zip(vals, lb, ub))    # does the check
    True
    

    An example that fails:

    >>> s = "5-9-90-15"    # fails with the third number
    >>> vals = [int(x) for x in s.split('-')]
    >>> all(x > L and x < U for x, L, U in zip(vals, lb, ub))
    False
    

    Regular expressions is the right tool if you need to extract the digit sequence from a larger string that has other text/characters in it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to find how to calculate the Floating/Double precision/range numbers -3.402823e38
I am trying to find the intersection of 2 number ranges, say for example...
I am trying to find whether a variable that I am calculating falls within
for practice purposes, I'm trying to find a way to print rows of numbers
I am trying to write a c++ program to find all numbers with a
I'm trying to find the most pythonic way to find out if numbers in
I'm trying to find the smallest number evenly divisible by each integer 1-20(inclusive). This
I'm trying to implement a number range using the gsub function between 1-200, but
Trying to find a standard. The CmdLet will process data - multiple input, defined
Trying to find a way to remove blank pages from a document I wrote

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.