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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:56:34+00:00 2026-06-13T21:56:34+00:00

Using c# I am trying to use regular expressions to get the value of

  • 0

Using c# I am trying to use regular expressions to get the value of a piece of text that appears after a colon. I know the field name, but there is a following colon that is in a variable position. The value would end at the next whitespace.

Thus:

KnownFieldName : Value

I’d then like to place the value into a group.

I’ve found a number of similar questions but none that actually points me in the direction of solving this.

This is part of a larger piece of code, but basically it fits in here:

     foreach (var v in fieldsToParse)
                {
                    var match = Regex.Match(line, v.pattern, RegexOptions.IgnorePatternWhitespace);

                    if (match.Success)
                        v.value = match.Groups[v.name].Value;
                }   
  • 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-13T21:56:36+00:00Added an answer on June 13, 2026 at 9:56 pm

    The regex you’re looking for should be something like (?<knownfieldname>[a-zA-Z]+)(\s+):(\s+)(?<value>[a-zA-Z]+) or knownfieldname(\s+):(\s+)(?<value>[a-zA-Z]+)

    This presumes that KnownFieldName and Value are both only alpha characters, of course. If numerics can come into it you may also want to add 0-9 to the ranges, or if anything but white space is really valid there you can just use the \S wildcard I guess.

    Edited to incorporate a variable number of spaces. Also, in light of the comments below, you might consider bookmarking both Derek Slager’s awesome Regex tester and this simple Regex cheat sheet. Helps a lot with situations like this.

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

Sidebar

Related Questions

I'm trying to use regular expressions to match a string that does not contain
I know that using Regular expressions to parse or manipulate HTML/XML is a bad
I am trying to get the text in between two keywords using a regular
I'm trying to match punctuations using regular expressions. Do I have to specify every
I'm trying to use Hpricot to get the value within a span with a
I am trying to get commented strings in my code using regular expression in
I'm trying to obtain data using regular expressions from a html file, by implementing
I'm trying to convert $(5.20) to -5.20 using regular expressions, but can't seem to
I'm trying to use a regular expression to validate a name entry field. The
I'm just getting to know regular expressions, but after doing quite a bit of

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.