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

  • SEARCH
  • Home
  • 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 7193293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:08:28+00:00 2026-05-28T20:08:28+00:00

I have to search a string for a few words eg, dog, cat, lion

  • 0

I have to search a string for a few words eg, dog, cat, lion but I want regex to fail if lizard is found in the string even if it contains cat, dog or lion.

ismatch(pass) "dog|cat|lion" "This is not your average cat!"

ismatch (fail) [my regex statement] "This is not your average cat! It's a lizard."

[my regex statement] – here the regex statement is unknown, can you please help me to write this statement?

Word spaces and boundaries or lower/uppercase is not a concern. I run the string through

Replace(" ", "").Trim(" ").ToLower 

before handover to Regex.

  • 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-05-28T20:08:31+00:00Added an answer on May 28, 2026 at 8:08 pm

    Try this using negative lookahead and negative look behind

    (?<!lizard.*)(?:dog|cat|lion)(?!.*lizard)
    

    If you use the Regex option ignore case you don’t need to call tolower. You can specify it by adding (?i) to the beginning of the regex string.

    After comment by js_dudley here is a way to build the string up

    var exclude=new string[] { "lizard","eagle"};
    var include=new string[] {"dog","cat","lion"};
    var regexString=string.Format(
                                    "(?<!({0}).*)(?:{1})(?!.*({0}))",
                                    string.Join("|",exclude),
                                    string.Join("|",include)
                                 );
    var regex=new Regex(regexString);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a folder full of files and I want to search some string
I have input.txt and I want to search for a string and extract a
I have a string s and I want to search for the substring of
I have a string of letters and I want to search it for a
i have a text file with string abcdef I want to search for the
I have the following controller: public ActionResult Search(string Name, int? Friend, int? Page) It
I have a search method that takes in a user-entered string, splits it at
I have a NSMutableArray that I need to search for a string and return
I have an active directory search function: Function GetAdInfo(ByVal ADDN As String, ByVal ADCommonName
I want to set up a search in Lucene (actually Lucene.NET, but I can

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.