Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8849781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:44:33+00:00 2026-06-14T12:44:33+00:00

I had a regex that detects when a string IS NOT the given pattern:

  • 0

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 http://www.test.com” is FALSE
But now I would liket to allow one URL: http://www.example.com.

It means:

” this is a test” > TRUE

“this is a test http://www.example.com” > TRUE

“this is a test example.com this” > TRUE

“this is a test http://www.test.com this” > FALSE

“this is a test test.com this” > FALSE

“this is a test test.com this http://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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:44:34+00:00Added an answer on June 14, 2026 at 12:44 pm

    In this case using two separate expressions might be the solution:

    OKAY_EXPR = /example\.com/
    BANNED_EXPR = /.../ # Existing expression
    
    if (string.match(OKAY_EXPR) and !string.match(BANNED_EXPR))
      # ...
    end
    

    It’s not clear what you’re doing here, but that does seem to be an extremely restrictive set of TLDs. There are literally thousands of valid TLDs which might need to be processed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a regex that replaced all URLs from a given string: my_string =
I had a quick question regarding RegEx... I have a string that looks something
Here is proof that my site is not portable. I had some regex that
I had this url regex pattern in place: $pattern = @\b(https?://[^\s()<>\[\]\{\}]{1,.$max_length_allowed_for_each_url.}(?:\([\w\d]+\)|([^[:punct:]\s]|/)))@; It seemed to
So for instance if I had this string : color=green&animal=panda Is it possible that
I'm trying to write a regex that will take a string of the form:
I had a regex, like so: (?<one-1>cat)|(?<two-2>dog)|(?<three-3>mouse)|(?<four-4>fish) When I tried to use this pattern
I had this regex in java that matched either an alphanumeric character or the
Uh, and it's broken: I had a perfectly working regex that allowed all the
I have a Regex pattern that matches data I need to parse exactly as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.