ruby regexp match all
# use scan
"hello".scan(/l/)
ruby regexp match all
# use scan
"hello".scan(/l/)
regex in rails
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}$')
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us