tags:

views:

58

answers:

2

So I have some text that I need to get an integer out of. Here's some examples of what the text could look like:

as low as $99

you can get it for $99 or less

I need to get the number out of the text, either with or without the $ sign.

Can I do this using Regex.Replace?

+4  A: 

I would use RegEx.Match. You can use the following regex: ([0-9]+)

This is assuming you don't have any commas, or decimals that may mess it up. If that is an issue, just add what else to look for inside the [].

The Match function will return an object that will tell you if there were any matches along with an array of the matches, and so you can easily get everything that was found.

davisoa
This worked, thanks.
Steven
+1  A: 

If you specifically want money values prefixed by $ you could use a look behind:

(?<=\$)[0-9\.]+
TheCodeKing