File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
EJB 3 in Action
this week in the
EJB and other Java EE Technologies
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)
I agree. Here's the link:
subject: Escaping special characters regex/function help
Escape single quotes
Generating Regular Expression at run-time
Regex help, replacing/espacing characters
how to read a file in a string
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014