Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

regex in rails

Model.where("column ~* ?", ''^Ad{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 ~* ?", '^Ad{4}$')
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #regex #rails
ADD COMMENT
Topic
Name
2+3 =