Given a string str containing numbers and alphabets, the task is to find all the numbers in str using regular expression.
Output: 11 15 678 4
Output: 1 133 0
Approach: The idea is to use Python re library to extract the sub-strings from the given string which match the pattern [0-9]+. This pattern will extract all the characters which match from 0 to 9 and the + sign indicates one or more occurrence of the continuous characters.
Below is the implementation of the above approach:
345 43 42
- Regular Expression in Python with Examples | Set 1
- Lambda expression in Python to rearrange positive and negative numbers
- Regular Expressions in Python | Set 2 (Search, Match and Find All)
- Python | Find the Number Occurring Odd Number of Times using Lambda expression and reduce function
- Python | Check whether string contains only numbers or not
- Python | Extract numbers from string
- Evaluate an array expression with numbers, + and -
- Python | Print all string combination from given numbers
- Python String | find()
- Extracting email addresses using regular expressions in Python
- Python program to find all Strong Numbers in given list
- Find length of a string in python (4 ways)
- Python | Find position of a character in given string
- Find all the patterns of “1(0+)1” in a given string using Python Regex
- Python | Ways to find all permutation of a string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.