A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Escaping special characters regex/function help
Joined: Feb 12, 2009
Jul 31, 2009 10:42:42
I needed a little help writing a function in
that does the follow for espacing, I want to use regular expressions, I need the following characters to be replaced by a “~”
The special characters are replaced as follows:
1. Newline, backspace, Control-M, carriage return, vertical tab characters are each replaced with "~"
2. Double quotes (") are replaced with single quotes (')
3. Then single quotes are escaped by inserting a backslash before each one.
Can someone give me a hand writing this? I don’t know regular expressions so it’s difficult for me to get going on this.
Joined: Oct 13, 2005
Jul 31, 2009 11:00:15
A good place to learn regular expressions is in the
Joined: Sep 28, 2004
Jul 31, 2009 11:20:27
I don’t know regular expressions so it’s difficult for me to get going on this.
I am a big believer that you should never use code that you don't understand. So, if you don't know regex, then you probably shouldn't use it.
Take a look at the
replace() methods. It will do what you want, and you don't need to know regex.
Java Threads, 3rd Edition
Jini in a Nutshell
Java Gems (contributor)
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
subject: Escaping special characters regex/function help
Regex help, replacing/espacing characters
Escape single quotes
how to read a file in a string
Generating Regular Expression at run-time
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014