You have two problems here - first is escaping of special regex symbols (end of line in your case). And second one is wrong pattern - your current solution tries to match @ right after digits:
one or more @ character
|
| end of line
| |
\d+@+$
|
one or more digit
That will be matched by hello1234@ which, of course, not your case. You want to remove either digits with dollar sign, or @ character. Here is correct pattern:
one optional $ character
|
| OR
| |
\d+\$?|@
| |
| @ character
|
one or more digit
Here is code:
string strAttachment = "[email protected],3470SQL.txt";
var result = Regex.Replace(strAttachment, @"\d+\$?|@", "");
Alternatively, if you just want to remove any digits, dollars and @ from your string:
var result = Regex.Replace(strAttachment, @"[\d\$@]+", "");
1 or more digitsand then1 or more @, and then the end of the line. This Regex is so far from what you want, I just don't get it. I really don't.