On Tue, 14 Sep 2004, Johnstone, Colin wrote:

> I found this regex by searching on google and I assumed the guy who 
> wrote it knew more than me.

>From the look of this regex, that ain't necessarily so.

The thing with regular expressions is that they tend to be crafted for 
very specific purposes, and unless this guy was trying to solve the 
exact same problem you are, the regex he wrote may not do what you need.
 
> I guess I was looking for a general purpose regex to remove invalid 
> characters from filenames to add to my developers toolkit to take from 
> project to project.

Shouldn't a toolkit consist of things you actually understand. 

It's like the old "give a man a fish" saying -- if as a result of this 
discussion you come away with a regex that solves this specific problem 
today, then you will be able to eat today. If on the other hand you 
start learning how regular expressions work, you'll be able to write 
your own ones and won't have to rely on questionable canned examples.
 
> Specifically for this project I would like to remove spaces and 
> ampersands apostrophes, quotes should users enter them.

That's nice.

As others asked you, what would you like to *keep* ? 

This regular expression can be much more simply expressed in terms of 
matching everything other than that which you know you want. You 
probably want letters, digits, and maybe some punctuation, right? Try to 
list all the characters that are valid in filenames on all the platforms 
that Teamsite currently or could potentially run on, and then you'll be 
most of the way to the regex you want. 


Also, if you just want to strip out bad characters a substitution regex 
(one with s/.../.../ syntax) may be much more complicated than a simple 
tr/...// statement. Have you tried doing it that way ?



-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to