Skip to content

Instantly share code, notes, and snippets.

@shazaum
Last active April 14, 2019 02:03
Show Gist options
  • Save shazaum/a4afaf28f607653f34de to your computer and use it in GitHub Desktop.
Save shazaum/a4afaf28f607653f34de to your computer and use it in GitHub Desktop.
regex custom
X = Regexp.new("[0-9]")
N = Regexp.new("[1-9]")
Z = Regexp.new("[2-9]")
match_number = "ZNX" # does not works, need convert to "#{Z}+#{N}+#{X}"
number = "210"
if (number =~ /#{match_number}/) # it works -> /#{Z}+#{N}+#{X}/
puts "match #{number}"
else
puts "NOK"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment