Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: leaving only [a-zA-Z0-9]

by dvergin (Monsignor)
on Mar 21, 2004 at 14:44 UTC ( #338459=note: print w/replies, xml ) Need Help??

in reply to leaving only [a-zA-Z0-9]

The other responses here give good solutions. But here's what went wrong with your approach.

You said /!([a-zA-Z0-9])/ in the regex part of your substitution, by which you meant, "match anything that is not a letter or number". But what you wrote actually means "match an exclamation point followed by any letter or number". Clearly not what you wanted.

The way to say what you wanted that is closest to what you wrote is, /([^a-zA-Z0-9])/. The caret as the first character in the character class does what you wanted the excalmation point to do. And the parentheses do nothing for you in the current instance so you can leave them out.

The tr/// example was recommended to you because, for tasks like this, it is faster, conceptually cleaner, and more idiomatic.

"Perl is a mess and that's good because the
problem space is also a mess.
" - Larry Wall

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://338459]
[Corion]: marto: Ooof - but yes, being there as only second level support or third level support is good and if you have enough things that you can work on, it won't be a wasted (if paid) day
[marto]: I've opted for a day off later on, rather than pay. I only have to do about 45 mins work for the client, but do need to hang around
[Corion]: marto: Even better ;)
[marto]: and I'm off next week1
[Corion]: Whee! ;)
[Corion]: I was away last week already, so I know how good a week off is ;))

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2017-02-28 10:08 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (399 votes). Check out past polls.