Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import re

def extract_numbers(input_string: str) -> list:
"""
Extract all numbers from a given input string.

This function accepts a string as input and returns a list of found numbers.
It uses regular expressions to match and extract integers, decimals, and
negative numbers from the input string.

Args:
input_string (str): The string to extract numbers from.

Returns:
list: A list of extracted numbers.

"""
pattern = r'-?\d+(\.\d+)?'
return re.findall(pattern, input_string)