Skip to content

Instantly share code, notes, and snippets.

@cdesch
Last active October 14, 2019 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdesch/af70cdc492fef1a19ca8 to your computer and use it in GitHub Desktop.
Save cdesch/af70cdc492fef1a19ca8 to your computer and use it in GitHub Desktop.
Rails Regex
#regex templates
#Subdomain
#ensure there are no special characters and the subdomain does not end with a - or _
/^[a-z\d]+([-_][a-z\d]+)*$/i
#title
/[a-zA-Z0-9.\s]+/i
# ensure secret contains at least one number
validates_format_of :secret, :with => /[0-9]/,
:message => "must contain at least one number"
# ensure secret contains at least one upper case
validates_format_of :secret, :with => /[A-Z]/,
:message => "must contain at least one upper case character"
# ensure secret contains at least one lower case
validates_format_of :secret, :with => /[a-z]/,
:message => "must contain at least one lower case character"
#resources
http://idiosyncratic-ruby.com/11-regular-extremism.html
# RubyMine Replace Regex https://regexr.com/4mqo1
Sample: Faker::Number.between(0, 1000)
Target: Faker::Number.between(from: 0, to: 1000)
Regex Search: between\(([0-9]), ([0-9]*)\)
Replace: between(from: $1, to: $2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment