So I have some text that I need to get an integer out of. Here's some examples of what the text cou开发者_开发知识库ld 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?
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.
If you specifically want money values prefixed by $
you could use a look behind:
(?<=\$)[0-9\.]+
精彩评论