extract_ints_from_str

strng.extract_ints_from_str(s)[source]

Extract all integers from a string.

Parameters:

s (str) – The input string.

Returns:

ints (list) – List of integers in s.

Examples

>>> extract_ints_from_str('I have 2 apples and 4 pears')
[2, 4]
>>> extract_ints_from_str('I have 2.5 apples and 4 pears')
[4]
>>> extract_ints_from_str('I have no apples and no pears')
[]
>>> extract_ints_from_str('I have -1 apples and -2.5 pears')
[]