I have a scenario where I have to remove certain characters from a price string using C#.
I\'m looking for a regular expression to remove these characters or somethi
Regular expressions are always tricky to get right, since the input can vary so greatly, but I think this one covers your needs:
string pattern = @"([\d]+[,.]{0,1})+";
string cleanedPrice = Regex.Match(price, pattern).Value;
Explained:
( - start matching group
[\d]+ - match any decimal digit, at least once
[,.]{0,1} - ...followed by 0 or 1 comma or dot
) - end of group
+ - repeat at least once