Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to remove all (non numeric OR period)

Tags:

c#

regex

I need for text like "joe ($3,004.50)" to be filtered down to 3004.50 but am terrible at regex and can't find a suitable solution. So only numbers and periods should stay - everything else filtered. I use C# and VS.net 2008 framework 3.5

like image 836
Ready Cent Avatar asked Jun 16 '10 17:06

Ready Cent


People also ask

How do you remove non numbers from a string?

In order to remove all non-numeric characters from a string, replace() function is used. replace() Function: This function searches a string for a specific value, or a RegExp, and returns a new string where the replacement is done.

How do I remove non numeric characters from R?

We will remove non-alphanumeric characters by using str_replace_all() method.

How do I remove a character from a number string?

Using 'str. replace() , we can replace a specific character. If we want to remove that specific character, replace that character with an empty string. The str. replace() method will replace all occurrences of the specific character mentioned.


1 Answers

This should do it:

string s = "joe ($3,004.50)"; s = Regex.Replace(s, "[^0-9.]", ""); 
like image 187
josephj1989 Avatar answered Sep 24 '22 21:09

josephj1989