import re
"""
This program extracts all integer values from a mixed string
and sorts them using the language's built‑in sorting mechanism.
It demonstrates:
- clear separation of concerns using functions
- efficient number extraction using regular expressions
- dynamic storage using lists
- fast sorting with sorted()
"""
# ------------------------------------------------------------
# Extract all integer values from a mixed string.
# Uses a regular expression to find digit sequences.
# ------------------------------------------------------------
def extract_numbers(text: str) -> list[int]:
# Find all sequences of digits in the string
matches = re.findall(r"\d+", text)
# Convert each match to an integer
return [int(m) for m in matches]
# ------------------------------------------------------------
# Print all numbers in a space‑separated format.
# ------------------------------------------------------------
def print_numbers(numbers: list[int]) -> None:
print(" ".join(str(n) for n in numbers))
# ------------------------------------------------------------
# Main
# ------------------------------------------------------------
def main() -> None:
text = "1000withz7 and3 or 99 give42"
# extract numbers
numbers = extract_numbers(text)
# sort numbers
numbers = sorted(numbers)
# display result
print("Sorted numbers:", end=" ")
print_numbers(numbers)
if __name__ == "__main__":
main()
"""
run:
Sorted numbers: 3 7 42 99 1000
"""