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

The Archive Base Latest Questions

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

Having a hard time explaining what I mean, so here is what I want

  • 0

Having a hard time explaining what I mean, so here is what I want to do

I want any sentence to be parsed along the pattern of

text #something a few words [someothertext]

for this, the matching sentence would be

Jeremy is trying #20 times to [understand this]

And I would name 4 groups, as text, time, who, subtitle

However, I could also write

#20  Jeremy is trying [understand this] times to

and still get the tokens
#20
Jeremy is trying
times to
understand this

corresponding to the right groups

As long as the delimited tokens can separate the 2 text only tokens, I’m fine.

Is this even possible? I’ve tried a few regex’s and failed miserably (am still experimenting but finding myself spending way too much time learning it)

Note: The order of the tokens can be random. If this isn’t possible with regex then I guess I can live with a fixed order.

edit: fixed a typo. clarified further what I wanted.

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

    You can alternate on the different types of text. Using named groups means that one group would have a Success value equal to true for each match.

    This pattern should do what you need:

    @"(?<Number>#\d+\b)|(?<Subtitle>\[.+?])|\s*(?<Text>(?:.(?!#\d+\b|\[.*?]))+)\s*"
    
    • (?<Number>#\d+\b) – matches # followed by one or more digits, up to a word boundary
    • (?<Subtitle>\[.+?]) – non-greedy matching of text between square brackets
    • \s*(?<Text>(?:.(?!#\d+\b|\[.*?]))+)\s* – trims spaces at either end of the string, and the named capture group uses an approach that matches a single character at a time provided that the negative look-ahead fails to match if it detects text that would match the other 2 text patterns of interest (numbers and subtitles).

    Example usage:

    var inputs = new[] 
    { 
        "Jeremy is trying #20 times to [understand this]",
        "#20 Jeremy is trying [understand this] times to"
    };
    string pattern = @"(?<Number>#\d+\b)|(?<Subtitle>\[.+?])|\s*(?<Text>(?:.(?!#\d+\b|\[.*?]))+)\s*";
    foreach (var input in inputs)
    {
        Console.WriteLine("Input: " + input);
        foreach (Match m in Regex.Matches(input, pattern))
        {
            // skip first group, which is the entire matched text
            var group = m.Groups.Cast<Group>().Skip(1).First(g => g.Success);
            Console.WriteLine(group.Value);
        }
        Console.WriteLine();
    }
    

    Alternately, this example demonstrates how to pair the named groups to the matches:

    var re = new Regex(pattern);
    foreach (var input in inputs)
    {
        Console.WriteLine("Input: " + input);
        var query = from Match m in re.Matches(input)
                    from g in re.GetGroupNames().Skip(1)
                    where m.Groups[g].Success
                    select new
                    {
                        GroupName = g,
                        Value = m.Groups[g].Value
                    };
        foreach (var item in query)
        {
            Console.WriteLine("{0}: {1}", item.GroupName, item.Value);
        }
        Console.WriteLine();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a hard time explaining this. Please let me know of any specific
Alright, I'm having a hard time explaining this, let me know if I should
I'm having a hard time understanding some git/DCVS concepts. Here's what happened: I created
Hi I am having hard time making C# type inference do what I want.
im having hard time with this one, i want to create folder with write
I am learning recursion and having hard time in tracing recursion. Here is my
I'm having hard time trying to set certain cell's value in table. Here is
I am having hard time with php headers, i'm trying to create any kind
I'm having a really hard time finding any examples that are close to what
I am having hard time understanding typedef pattern for arrays. typedef char Char10[10]; void

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.