Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to extract digits from a string in python

# Get digit using regex
import re

def extract_num_from_string(string: str) -> int:
  return ''.join(re.findall('d', string))

print(extract_num_from_string('Year 2000'))

# output will be: 2000
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #extract #digits #string #python
ADD COMMENT
Topic
Name
9+1 =