I’m adding a validation check on a rails model using the following regex:
validates :reference, :presence => true, :format => { :with => /^[a-zA-Z0-9_. ]*$/i }
This check will match any non alphanumeric chars and ignores underscore and dot.
When testing on rubular.com, the regex fails to match any of the above mentioned patterns. Instead, rubular matches using this regexp:
/[^a-zA-Z0-9_. ]/i
Anyone knows what the reason behind the difference between the two?
Thanks
^has two meanings. When used outside of brackets, it means “line begins with”. When used inside brackets, it means that what is matched is the opposite. I feel like I’m not clear so :[a-z]would match every lower case letter, while[^a-z]would match anything but a lower case letter.