語言是紅寶石,這裏是我的IRB會議爲什麼我的正則表達式中的最後一個表達式連接到第一個表達式?
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
我只是不明白,爲什麼我是「按價值遞減實體令」得到$ 1美元。這裏期望的行爲是獲得$ 1 =>「實體」,$ 2 =>「值」,$ 3 =>「desc」。我究竟做錯了什麼?我如何修改這個正則表達式,以便得到這些結果?
謝謝