I have a regex to filter data
#Matches Result
Homeowner's Insurance Premium ( 12 mo.) toAmerican Family $893.00
Insura
Mortgage Insurance Premium ( mo.)
Prepaid Interest ($5.99 per day from 10/02/2020 to 10/01/2020) -$5.99
Using for each loop on the Matches activity above , I want to remove all dollars like $893.00 , $5.99 etc using the ff. regex , but it does no work . any idea ? thanks.
(.*)\s\$\d[\d.]*([^\r\n]*)(?:\r?\n(?!\d+ )(.+))?
System.Text.RegularExpressions.Regex.Replace(item,"(.*)\s\$\d[\d.]*([^\r\n]*)(?:\r?\n(?!\d+ )(.+))?" , "")
To remove the dollar amount at the end of the string you can use
Regex.Replace(item, @"\s*[+-]?\$\d*\.?\d+\s*$", "")
Make sure you use a verbatim string literal, @"..."
, in C# code (it is not needed in VB.NET though), to be able to use a single \
as the regex escape char.
The pattern means
\s*
- 0+ whitespaces[+-]?
- an optional -
or +
\$
- a $
char\d*
- 0 or more digits\.?
- an optional .
\d+
- 1+ digits\s*
- 0 or more whitespaces$
- end of string.See the RegexStorm regex demo online (click the Context tab at the bottom to see the replacement result).