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 8652167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:14:47+00:00 2026-06-12T14:14:47+00:00

I though that filtering a string like : Hello <strong>plip</strong> plop to obtain plip

  • 0

I though that filtering a string like :
"Hello <strong>plip</strong> plop"
to obtain
"plip plop", that is, excluding all words except ‘plip’ and ‘plop’ would be easy with this C# line:
new Regex("[^(plip)(plop)]").Replace(inputString,"").
Unfortunalty, the excluding brackets [^] seem to not accept exclusion words, as it keeps each letters contained in ‘plip’ and ‘plop’ (the result is "llooplipoplop").

Is there a way to achieve this in a single regex/line, or is it necessary to loop other all matches of plip and plop, then concat them?

  • 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-12T14:14:48+00:00Added an answer on June 12, 2026 at 2:14 pm

    Generally speaking, it is much easier to write a regex that matches what you do want than one that matches all the stuff you don’t want.

    In this case you want to “exclude all words except plip and plop“, but why not just include only plip and plop instead?

    var input = "Hello <strong>plip</strong> plop";
    var matches = Regex.Matches(input, "plip|plop");
    var result = string.Join("", matches.Cast<Match>().Select(x => x.Value));
    
    Console.Out.WriteLine(result); // prints "plipplop"
    

    Of course since you asked for a one-liner, you could do everything without the temp variables (and good luck to the next guy reading the code!):

    var result = string.Join("", Regex.Matches("Hello <strong>plip</strong> plop", "plip|plop").Cast<Match>().Select(x => x.Value));
    

    Also, assuming you actual word list is more complicated than plip and plop, you can do something like var pattern = string.Join("|", words); to construct the pattern.

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

Sidebar

Related Questions

One would expect that even though strings are immutable, value-equality and reference-equality would not
I would like to implement a user-configurable filtering system for lists in an ASP.NET
I have an array of dictionaries. I would like to filter that array by
I though that Wikipedia uses a nice way of writing languages in their URLs:
My application uses MS access database to save some sensitive information. Though that information
I am writing a small application with Qt 4.6 (64-bit Arch Linux, though that
I've stumbled upon something which confuses me. Before I though that if you save
I have six SQL queries that I script though R that each take a
Given this hash that comes though :params positions=>{ 1=>{x=>50, y=>30}, 2=>{x=>22, y=>53}, 3=>{x=>68, y=>35}
I have a problem of web pages being cached even though I specify that

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.