How do I scan for combinations of words in ruby using regex? -
i'm trying scan string combination of list of words. specifically, want find 'number word' combinations such "two hundred , eighty" or "fifty eight".
to have made list single number words million:
numberwords = ["one", "two", "three", ...... "hundred", "thousand", "million"] i joined list using "|" , made regex this:
string.scan(/\b(#{wordlist}(\s|\.|,|\?|\!))+/) i expected return list of number word combinations returns words separately. example, if there "three million" in string returns "three" , "million" not "three million". how correct this?
numberwords = ["one", "two", "three", "hundred", "thousand", "million"] numberwords = regexp.union(numberwords) # => /one|two|three|hundred|thousand|million/ "foo bar 3 million dollars" .scan(/\b#{numberwords}(?:(?:\s+and\s+|\s+)#{numberwords})*\b/) # => ["three million"]
Comments
Post a Comment