rubular allows to test this regular expression
U\d{8}
Testing in the console
string = 'u12345678'
=> "u12345678"
my_regex = /^U\d{8}$/
=> /^U\d{8}$/
string.match?(my_regex)
=> false
string.upcase.match?(my_regex)
=> true
The latter syntax preference is preferred to /^U\d{8}$/i
.
How should the regex be manually input in the form and saved to the database?
Aside from the datatype being string, potential serialization and or encoding issues come to mind... the Ruby doc only provides indications for the latter issue
you can save source
as string (bytes array in UTF-8) and options
as uint
looks like uint8 is enough for options
or even uint5 (5 bits) if possible:
https://docs.ruby-lang.org/en/master/Regexp.html#method-i-options
and here is method to create reg exp by source and options:
https://docs.ruby-lang.org/en/master/Regexp.html#method-c-new
r = Regexp.new('foo') # => /foo/
r.source # => "foo"
r.options # => 0
Regexp.new('foo', 'i') # => /foo/i
Regexp.new('foo', 'im') # => /foo/im