Problem with replaceAll

G

Gaurav

Hi all,
I am having a problem with the replaceAll(str1,str2) method in java.
I am actually taking a substring from a user input, parsing it and then
I am doing:
userInput = userInput.replaceAll(str1,str2)
where str1 = some substring from user input
str2 = return value from someFunction(str1)

This works fine when user input does not contain parenthesis or any
other java.util.regex special characters. My code stops working in
case of regex special characters and I get str1 as the output of
replaceAll.
TIA
Gaurav
 
R

Roedy Green

H

hilz

Gaurav said:
Hi all,
I am having a problem with the replaceAll(str1,str2) method in java.
I am actually taking a substring from a user input, parsing it and then
I am doing:
userInput = userInput.replaceAll(str1,str2)
where str1 = some substring from user input
str2 = return value from someFunction(str1)

This works fine when user input does not contain parenthesis or any
other java.util.regex special characters. My code stops working in
case of regex special characters and I get str1 as the output of
replaceAll.
TIA
Gaurav



check out this:
http://mindprod.com/jgloss/string.html

(compliments of Roedy!)

look at the "Replace" section.
 
G

Gaurav

Thanx a lot for the link, guys. It solved my problem.I used \Q.....\E
and it worked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top