Regex help

  • Thread starter Thread starter Bryan Young
  • Start date Start date
B

Bryan Young

I want to generate a usable filename (no path, drive letter, or extension)
from strings from various sources (dates, database fields, user entry, etc).
I'm trying to use the following line and regex to replace any invalid
characters with an empty string. However, it doesn't work. I've tested the
expression with RegExBuddy and it says it is fine and does what I want. I
am aware of some bugs in the .Net Framework 1.0 regarding regex, but this is
a 1.1 application. Any help would be appreciated.

Regex.Replace(FileName,"[^\\w$%_@~`!(){}^#&-]*",string.Empty);



Bryan
 
I want to generate a usable filename (no path, drive letter, or
extension) from strings from various sources (dates, database fields,
user entry, etc). I'm trying to use the following line and regex to
replace any invalid characters with an empty string. However, it
doesn't work. I've tested the expression with RegExBuddy and it says
it is fine and does what I want. I am aware of some bugs in the .Net
Framework 1.0 regarding regex, but this is a 1.1 application. Any
help would be appreciated.

Regex.Replace(FileName,"[^\\w$%_@~`!(){}^#&-]*",string.Empty);

Are you sure you are using the same regex in your code and your RegexBuddy?
Because from what I see, this regex does the exact opposite of what you
want. It takes out everything BUT the characters you have specified. I
suggest taking out the ^ near the beginning.

Maybe you can give some examples of your input and what you get for output?

-mdb
 
Back
Top