Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Regular Expression Currency

I am trying to find the currency in strings like "NTE $22,539,420.00"

I tried to use several regular expressions including ^\s*[\+-]?\s?\$?\s?(\d*\.?\d{2}?){1}$ but none of them seem to work. Does anyone have any suggestions or reasons why the above would not work.

Thanks, Jim

like image 601
Jim Avatar asked Aug 03 '26 18:08

Jim


1 Answers

Could you just dump all the formatting (except for the decimal) like so?

string money = "NTE $22,539,420.00";
string scrubbed = Regex.Replace(money, @"[^0-9\.]", string.Empty);

At this point, scrubbed contains 22539420.00.

like image 113
arcain Avatar answered Aug 06 '26 08:08

arcain