I had a regex that detects when a string IS NOT the given pattern:
/\A((?!.*(www|http|@|\.com\b|\.net\b|\.de\b|\.info\b)).*)$/m
It means that strings like "hi you at www.test.com" is FALSE But now I would liket to allow one URL: www.example.com.
It means:
" this is a test" > TRUE
"this is a test www.example.com" > TRUE
"this is a test example.com this" > TRUE
"this is a test www.test.com this" > FALSE
"this is a test test.com this" > FALSE
"this is a test test.com this www.example.com " > FALSE (false because one forbiden URL is present)
It seems I need to include an AND operator, I think it is:
(?=.*PATTERN)
but unfortunately I couldn't make it work.
ps: I know that this regex that detects urls is not perfect at all, but because my requirements it is bettern than nothing.
Thanks !
Edit: My regex is located in a validator:
def self.validates_is_url_and_email_free(*attr_name)
validates_format_of attr_name, {:with => /\A((?!.*(www|http|@|\.com\b|\.net\b|\.de\b|\.info\b)).*)$/m, :message => I18n.t(:not_url_email)}
end