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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -