Regex help

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
 
M

Michael Bray

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top