This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
String name has some value which contains some special characters. I want all characters apart from A-Z a-z 0-9 . (dot) _ (underscore) - (hyphen) to be replaced with an _ (underscore)
So I should get 12E463_1.jpg in newName
But using the above regex the opposite happens. All characters apart from the special character (~ in this case) gets replaced. Please tell me how to do the opposite of the above regex.
Thanks for replying. But I want all the characters apart from
A-Z a-z 0-9 . (dot) _ (underscore) - (hyphen) to be replaced with an _ (underscore)
Alan Moore
Ranch Hand
Joined: May 06, 2004
Posts: 262
posted
0
To invert a character class, add '^' to the beginning of it: Also, you want to use the + (one or more) quantifier instead of * (zero or more). Otherwise, you end up inserting an underscore at every other position.
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
posted
0
I'm not sure you need a + either.
If you use a +, you will replace each sequence of special characters with a single underscore. If you omit the + (and don't use * either), you will replace each individual special character with an underscore. Depends which result you want. [ March 20, 2007: Message edited by: Peter Chase ]
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P