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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:10:35+00:00 2026-05-13T21:10:35+00:00

I am trying to obtain the value part of this syntax: [name:value] I got

  • 0

I am trying to obtain the value part of this syntax:

[name:value]

I got as far as:

\[name:(\w*)]

Which matches the entire thing. Does anyone know the changes I would need to make to select only value? (Bearing in mind that syntax will also be surrounded by other text.

  • 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-13T21:10:35+00:00Added an answer on May 13, 2026 at 9:10 pm

    The Match.Result method is what you want. See API documentation and documentation on Regex substitution patterns.

    Use Regex.Match(input, pattern).Result("$1") to get what you want.

    To give a complete example, here is the unit test I used to confirm that this solution would work:

    [Test]
    public void TestRegexMatchResult() {
        var input = "Other text [name:value] and other text";
        var pattern = @"\[name:(\w+)\]";
    
        Assert.AreEqual("value", Regex.Match(input, pattern).Result("$1"));
    }
    

    The test passes.

    You can also go through a string and extract multiple occurrences of the pattern:

    [Test]
    public void TestRegexMatchesResult() {
        var input = "Some [name:value] pairs [name:something] here.";
        var pattern = @"\[name:(\w+)\]";
    
        var results = Regex.Matches(input, pattern).OfType<Match>()
            .Select(match => match.Result("$1"));
    
        Assert.AreEqual(2, results.Count());
    
        Assert.AreEqual("value", results.ElementAt(0));
        Assert.AreEqual("something", results.ElementAt(1));
    }
    

    Finally, if you need to abstract this to something other than “name”, you can do this:

    [Test]
    public void TestMatchingNameAndValue() {
        var input = "[key:value] [another_key:some_other_value]";
        var pattern = @"\[(\w+):(\w+)\]";
    
        var results = Regex.Matches(input, pattern).OfType<Match>()
            .Select(match => new KeyValuePair<string, string>(
                match.Result("$1"),
                match.Result("$2")));
    
        Assert.AreEqual(2, results.Count());
    
        Assert.AreEqual("key", results.ElementAt(0).Key);
        Assert.AreEqual("value", results.ElementAt(0).Value);
        Assert.AreEqual("another_key", results.ElementAt(1).Key);
        Assert.AreEqual("some_other_value", results.ElementAt(1).Value);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find a MySQL query which will obtain the time that is
I am trying to parse a hashmap that contains name-value pairs... The entities stored
I have spent the better part of today trying to figure this out and
I am currently trying to obtain the alpha value of a pixel in a
I am trying to obtain the minimum value from a worksheet however when I
I am performing an HTTP POST of a name/value pair and then trying to
I get this error while trying to obtain the number of shares and likes
I am trying to use the following code to obtain the result value, but
I am trying to obtain a field's value via reflection. The problem is I
I want to obtain the last value that I put in. I am trying

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.