Question

In python write a regular expression that exactly matches the numbers between 5000 and 9999

In python write a regular expression that exactly matches the numbers between 5000 and 9999

Homework Answers

Answer #1

Python code:

import re
#defining regex to match numbers between 5000-9999
regex='[5-9][0-9][0-9][0-9]'
#obtaining number to test
num=input()
#checking for match
match=re.search(regex,num)
#checking if number is in range
if match:
#printing it
print("Number is in range")
else:
#printing Number is not in range
print("Number is not in range")

Screenshot:


Input and Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
- Write a python program which prints all the numbers between 1 and 100 that are...
- Write a python program which prints all the numbers between 1 and 100 that are divisible by 3.
Write A python program to return all matches for a given search keyword to return the...
Write A python program to return all matches for a given search keyword to return the matched indexes. Hint use string.find(search, begin, end) recursively or in interation
Write regular expressions that will match IP addresses and usernames in a Microsoft IIS log file....
Write regular expressions that will match IP addresses and usernames in a Microsoft IIS log file. First, you will write a regular expression that matches IP addresses within the re.compile function call on line 36. Next, you will write a regular expression that matches usernames (in the format domain\username) on line 50. Finally, in steps 3 and 4 you will write a loop for each step that displays all the IP addresses (gathered into the list ipAddresses) and usernames (gathered...
Write an assembly code for a M68CH12 microcontroller that counts from 0000-9999 using even numbers on...
Write an assembly code for a M68CH12 microcontroller that counts from 0000-9999 using even numbers on the seven segment display.
Write a Python program to manage league matches. Different teams can participate in a league. A...
Write a Python program to manage league matches. Different teams can participate in a league. A player belongs to a team and a team can play many games in a league. For each team the league wants to track the name of the team and the number of players in each team. The league also wants to track the number of games the team has played, and the total numbers of points scored across all games played. During each game...
Write the regular expression that will match the following string pattern descriptions. A space character at...
Write the regular expression that will match the following string pattern descriptions. A space character at the beginning of a line Upper case vowel one and more lines with a length of exactly 80 characters A single character that cannot be an alpha or a digit A dollar sign character ‘$’ at the end of the line
PYTHON 3 Write a program that prints the count of all prime numbers between A and...
PYTHON 3 Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = 21212 B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules: You should first...
Write python code that reads a string with numbers and letters and outputs sum of the...
Write python code that reads a string with numbers and letters and outputs sum of the numbers and number of letters.
Write a Python expression that uses the list even_numbers below and evaluates to the list [4]....
Write a Python expression that uses the list even_numbers below and evaluates to the list [4]. or produces the list to [4] even_numbers = [0, 2, 4, 6, 8, 10, 12]
How do you write a python function that prints numbers contained within a range of numbers...
How do you write a python function that prints numbers contained within a range of numbers ( for example 300 to 400) and the numbers printed by the function are self-divisible by all digits in the number. Could you assist?
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT