char « replace « Java Regex Q&A

Home
Java Regex Q&A
1.Development
2.find
3.group
4.Match
5.matcher
6.number
7.Operation
8.parse
9.Pattern
10.replace
11.validation
12.word
Java Regex Q&A » replace » char 

1. replace a set of characters with another set of chars (in pair): "&", "&" "<", "<" etc. in regex    stackoverflow.com

I have to encode the 5 XML reserved chars (& < > " and ') properly as follows:

"&", "&amp;" "<", "&lt;" ">", "&gt;"
   "\"", "&quot;" "\'", "&apos;"
I can do ...

2. Replace "^" char    stackoverflow.com

I'm trying to replace the "^" character on a String using:

String text = text.replaceAll("^", "put this text");
If text as the following value:
"x^my string"
The resulting String is:
"put this textx^my string"
This only happens ...

3. How avoid replacement of new line char in regex string replacement?    coderanch.com

Hi all, I have the following code, public static void test2() { String newLine = System.getProperty("line.separator"); String TOKEN="TOKEN"; String s = "abc maulin vasavada"; StringBuffer sb = new StringBuffer(); sb.append(s).append(newLine). append(s).append(newLine). append(s); String s1 = sb.toString(); System.out.println(s1); s1 = s1.replaceAll("\\s+",TOKEN); System.out.println(s1); } Here the problem is, "\\s+" pattern matches the newlines in the string and replace them with TOKEN. I want ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.