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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:38:45+00:00 2026-05-15T04:38:45+00:00

I’m pretty new to using regexes and I can figure out how I would

  • 0

I’m pretty new to using regexes and I can figure out how I would go about extracted a specific number from a string.

Suppose the string was any amount of whitespace or random text and somewhere within it is this, “Value: $1000.00.”

In order to retrieve that value I am currently using this:

string value = Convert.ToString(Regex.Match(BodyContent, @"Value:[ \t]*\$?\d*(\.[0-9]{2})?", RegexOptions.Singleline));

So the variable ‘value’ now has, “Value: $1000.00” stored in it.

My question is, using Regex is there a way to use ‘Value:’ to find the number value but only store the actual number value (i.e. 1000.00) in the ‘value’ variable?

  • 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-15T04:38:45+00:00Added an answer on May 15, 2026 at 4:38 am

    Generally speaking, to accomplish something like this, you have at least 3 options:

    • Use lookarounds (?=...), (?<=...), so you can match precisely what you want to capture
      • Some languages have limited support for lookbehinds
    • Use capturing group (...) to capture specific strings
      • Near universally supported in all flavors
    • You can also just take a substring of the match
      • Works well if the length of the prefix/suffix to chop is a known constant

    References

    • regular-expressions.info/Lookarounds and Groups

    Examples

    Given this test string:

    i have 35 dogs, 16 cats and 10 elephants
    

    These are the matches of some regex patterns:

    • \d+ cats -> 16 cats (see on rubular.com)
    • \d+(?= cats) -> 16 (see on rubular.com)
    • (\d+) cats -> 16 cats (see on rubular.com)
      • Group 1 captures 16

    You can also do multiple captures, for example:

    • (\d+) (cats|dogs) yields 2 match results (see on rubular.com)
      • Result 1: 35 dogs
        • Group 1 captures 35
        • Group 2 captures dogs
      • Result 2: 16 cats
        • Group 1 captures 16
        • Group 2 captures cats

    Solution for this specific problem

    It’s much simpler to use capturing group in this case (see on ideone.com):

    var text = "Blah blah Value: $1000.00 and more stuff";
    string value = Convert.ToString(
       Regex.Match(
         text,
         @"Value:[ \t]*\$?(\d*(\.[0-9]{2})?)",
         RegexOptions.Singleline
       ).Groups[1]
    );
    

    The only thing that was added was:

    • A pair of matching parantheses in the pattern to capture the numeric portion
    • Accessing .Groups[1] of the Match object
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you

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.