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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:24:08+00:00 2026-05-23T07:24:08+00:00

Given a collection of word combinations, is it possible to return a collection of

  • 0

Given a collection of word combinations, is it possible to return a collection of matched word sets and extract those from a given string using RegEx?

For example, given a car list:

mazda 3
mazda 4
volvo s40

The following text is used:
“I wanted to buy a mazda 3 however I found the volvo s40 to be a much better deal with the 90gv tires.”

I how want two different lists from this that should return:

{mazda 3, volvo s40, 90gv} 
{I, wanted, to, buy, a, however, I, found, the, to, be, a, much, better, deal, with, the, tires}
  • 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-23T07:24:08+00:00Added an answer on May 23, 2026 at 7:24 am

    This code uses a MatchEvaluator for the matches (the car models), and returns “”, so the model gets replaced with empty string. cars is a list of car models. words is a list of the remaining words. I’ll leave it to you to handle punctuation appropriately for your needs.

    List<string> cars = new List<string>();
    string input =
       "I wanted to buy a mazda 3 however I found the volvo s40 to be a much better deal.";
    string line = Regex.Replace(
       input, @"\b\w+\s+(?=\S*?\d)(?:\w+)",
       m =>
          {
             cars.Add(m.Value);
             return "";
          });
    string [] words = line.Split(' ');
    
    // Ouput the lists:
    Console.Write ("Cars:");
    foreach (string car in cars)
       Console.Write(car + "    ");
    Console.WriteLine ();
    Console.Write ("words: ");
    foreach (string word in words)
       Console.Write(word + " ");
    

    Produces this output:

    Cars:mazda 3    volvo s40
    words: I wanted to buy a  however I found the  to be a much better deal.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a collection of Word objects, I want to display a scrollable tag cloud
Need example how to create new local database and a connection string, if possible
I'd like to make some operations according to a given collection type (using reflexion),
im getting a CFDictionaryAddValue(): immutable collection 0xd5aea0 given to mutating function error when i
Given: Several million records in a mongo collection. Each record has 10 fields, of
Given a .net 4. collection, if I want to pass in my own custom
Given: <TextBox Text='{Binding MyCollection[MyIndex].MyProperty}'/> where: MyCollection is an observable collection of MyClass items MyClass
Given the following XML structure: <root> <data>x</data> <details> <some_other_element>...</some_other_element> <collection> <element><a>1</a></element> <element><a>2</a></element> <element><a>3</a></element> <collection>
I am building a .NET application that given a connection string, at run time,
I have given client's queue connection details to connect to it using Camel. While

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.