# Exercise: Finding Matches
#
# regex.find returns the first match:
#   regex.find ( String String -- String Bool )
#
# regex.find-all returns all matches as a list:
#   regex.find-all ( String String -- List Bool )
#   Returns list and success Bool (false if regex is invalid)
#
# Example:
#   "a1 b2 c3" "[0-9]" regex.find           # ( "1" true )
#   "a1 b2 c3" "[0-9]" regex.find-all drop  # ["1", "2", "3"]
#
# Your task: Extract data using regex
# When done, delete the marker line below.

# I AM NOT DONE

: find-first-number ( String -- String Bool )
    # Find the first sequence of digits
    # Your code here
    drop "" false
;

: find-all-words ( String -- List )
    # Find all sequences of word characters (\w+)
    # Return only the list (drop the success Bool)
    # Your code here
    drop list-of
;

: test-find ( -- )
    # Find first number
    "Order #42 shipped" find-first-number
    # Do not edit below this line
    test.assert
    "42" test.assert-eq

    # No number found
    "no numbers" find-first-number
    not test.assert
    drop

    # Find all words
    "hello, world! how are you?" find-all-words
    list.length 5 test.assert-eq
;
