The language is Ruby, here is my irb session
expr = /\Aselect from (\D+)(?: (?:where|&&) (\D+) (\S+) (\S+))*(?: order by (\D+) (asc|desc))?\Z/
=> /\Aselect from (\D+)(?: (?:where|&&) (\D+) (\S+) (\S+))*(?: order by (\D+) (asc|desc))?\Z/
/> str = "select from Entity order by value desc"
=> "select from Entity order by value desc"
/> expr =~ str
=> 0
/> $1
=> "Entity order by value desc"
/> $2
=> nil
I just don't understand why I am getting "Entity order by value desc" as $1. The desired behavior here would be to get $1 => "Entity", $2 => "value", $3 => "desc". What am I doing wrong? How do I modify this regular expression so I get these results?
Thank you