다음 변수에 정규식을 보관하고 있습니다 -
pattern_text = "/\A([^@\s]+)@((?:c-d+\.)+(in|com))\z/".
"mailbox@c-d.in".match?(/\A([^@\s]+)@((?:c-d+\.)+(in|com))\z/) => returns true
Regexp.new(pattern_text) => returns /\/A([^@ ]+)@((?:c-d+.)+(in|com))z\//
"mailbox@c-d.in".match?(Regexp.new(pattern_text)) => returns false
이 정규식을 데이터베이스에 저장하면 \가 자동으로 사라집니다.
제가 받는 정규식 검증기는 문자열로 들어옵니다. 왜 이 형태는 동작하지 않을까요?
영어에서 번역·원문 보기I am keeping a regular expression in the following variable -
pattern_text = "/\A([^@\s]+)@((?:c-d+\.)+(in|com))\z/".
"mailbox@c-d.in".match?(/\A([^@\s]+)@((?:c-d+\.)+(in|com))\z/) => returns true
Regexp.new(pattern_text) => returns /\/A([^@ ]+)@((?:c-d+.)+(in|com))z\//
"mailbox@c-d.in".match?(Regexp.new(pattern_text)) => returns false
Saving this regular expression to my database automatically strips the \.
The regex validator that I receive arrives as a string. Why doesn't that version work?