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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:12:52+00:00 2026-06-10T19:12:52+00:00

I have a dictionary defined as Dictionary<int, Regex> . There are a number of

  • 0

I have a dictionary defined as Dictionary<int, Regex>. There are a number of compiled Regex objects within this. This was done using C# .NET 4.

I’m trying to use a Linq statement to parse the dictionary and return an object that contains all of the dictionary Keys and the index of where each Regex was found in the specified text.

The IDs return fine, but I’m unsure of how to get the location of where the text was found. Can someone help me out?

var results = MyDictionary
    .Where(x => x.Value.IsMatch(text))
    .Select(y => new MyReturnObject()
        {
            ID = y.Key,
            Index = ???
        });
  • 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-10T19:12:53+00:00Added an answer on June 10, 2026 at 7:12 pm

    Use the Index property of the Match class instead of doing simple IsMatch.


    Example:

    void Main()
    {
        var MyDictionary = new Dictionary<int, Regex>() 
        {
            {1, new Regex("Bar")},
            {2, new Regex("nothing")},
            {3, new Regex("r")}
        };
        var text = "FooBar";
    
        var results = from kvp in MyDictionary
                      let match = kvp.Value.Match(text)
                      where match.Success
                      select new 
                      {
                            ID = kvp.Key,
                            Index = match.Index
                      };
    
        results.Dump(); 
    }
    

    Result

    enter image description here

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

Sidebar

Related Questions

I have defined a class Listener and created a dictionary of Listener objects. Each
I have four level data structure defined like this: Dictionary<Type1, Dictionary<Type2, Dictionary<Type3, List<Type4>>>> The
I have code that has a Dictionary defined as: Dictionary<int, StringBuilder> invoiceDict = new
I have a database table that is a dictionary of defined terms -- key,
I have a dictionary, user_dict, and create a list for each user value, this
i have this dictionary: a) 2012 UN NEWNW = ( 2012/06/04 Saudi Arabia Huge
I have defined a dictionary that I would like to pass around to various
I have a singleton object and have a dictionary defined in it. public class
I have a dictionary with an array in it defined as: Dictionary<string, string[]> wordDictionary
I defined this multi dimensional array in C#: int[,] values = new int[,] {

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.