wood burning stoves 2.0*
The moose likes Java in General and the fly likes regular expressions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "regular expressions" Watch "regular expressions" New topic

regular expressions

Joseph Sweet
Ranch Hand

Joined: Jan 29, 2005
Posts: 327
hi friends,

I need to escape of single quote "'" and backslash "\".
is the following doing this?

later i need to return to the original string, do i need to do this:

We must know, we will know. -- David Hilbert
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

a) looks like if you're trying to escape double quotes, not backslash.
b) to replace a backslash by an 'x', use:

The regexpressions use backslash as escape-character, so you have to give two of them.
But javac uses an backslash as escape-character too, so you have to preceede every backslash with another one, which leads to 4 backslashes in total.
Fortunately bb-code doesn't use backslashes itself - else I had to use 8 to make you see 4.

If you use a variable, you may print it out, if things get more complex:

[ May 12, 2005: Message edited by: Stefan Wagner ]

It is sorta covered in the JavaRanch Style Guide.
subject: regular expressions
Similar Threads
question about replace(',','')
Char Conversion
Eliminating new line characters from a string
escaping html characters and a string starting with double quote
Strign.replace() replaceAll()