w3resource logo


Python Exercises

Python: Search the numbers (0-9) of length between 1 to 3 in a given string

Python Regular Expression: Exercise-18 with Solution

Write Python program to search the numbers (0-9) of length between 1 to 3 in a given string.

Sample string :

"Exercises number 1, 12, 13, and 345 are important"

Sample Solution :-

Python Code :

import re
results = re.finditer(r"([0-9]{1,3})", "Exercises number 1, 12, 13, and 345 are important")
print("Number of length 1 to 3")
for n in results:
     print(n.group(0))

Python Code Editor:

import re
results = re.finditer(r"([0-9]{1,3})", "Exercises number 1, 12, 13, and 345 are important")
print("Number of length 1 to 3")
for n in results:
     print(n.group(0))

Improve this sample solution and post your code through Disqus



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program