“Руководитель в рельсах” Ответ

Рельсы, где регулярно

@max_draw = Drawing.where("drawing_number ~* ?", '^A\d{4}$')
Puzzled Peacock

Ruby Match Word в строке

text = "A regular expression is a sequence of characters that define a search pattern."

puts 'Found "A" at the beginning of the string.' if text.match(/^A/)
puts 'Found "O" at the beginning of the string.' if text.match(/^O/)

puts 'Found the string "character".' if text.match(/character/)
puts 'Found the word "character".' if text.match(/character\b/)
Pleasant Porcupine

Руководитель в рельсах

Model.where("column ~* ?", ''^A\d{4}$'')

^ - string start anchor
A - literal "A"
\d+ - one or more digits (0-9)
\d{4} - exactly four digits
$ - string end anchor

Basically, the regex reads "the string should start with an A, followed by 
four digits and then the string should end". The final query line is:

@max_draw = Drawing.where("drawing_number ~* ?", '^A\d{4}$')
Blue-eyed Bison

Ответы похожие на “Руководитель в рельсах”

Вопросы похожие на “Руководитель в рельсах”

Смотреть популярные ответы по языку

Смотреть другие языки программирования