
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to extract numbers from a string using Python?
To extract each digit from a string −
>>> str1='a34e 345 bcd 5he 78 xyz' >>> for s in str1: if s.isdigit():print (s) 3 4 3 4 5 5 7 8
To extract only integers from a string in which words are separated by space character −
>>> str1='h3110 23 cat 444.4 rabbit 11 2 dog' >>> for s in str1.split(): if s.isdigit(): print ((s)) 23 11 2
- Related Articles
- How to extract numbers from a string in Python?
- How to extract numbers from a string using regular expressions?
- How to extract numbers from text using Python regular expression?
- Extract decimal numbers from a string in Python \n\n
- How to extract date from a string in Python?
- Python – How to Extract all the digits from a String
- How to extract certain substring from a string using Java?
- How to extract a substring from inside a string in Python?
- How to extract data from a string with Python Regular Expressions?
- Python – Extract Percentages from String
- Extract a number from a string using JavaScript
- How to extract the first n characters from a string using Java?
- How to extract the last n characters from a string using Java?
- Python Regex to extract maximum numeric value from a string
- How to extract an HTML tag from a String using regex in Java?

Advertisements