S
Stephan Ehlert
Hi,
I have a problem with java.regex. In a given String \\ has to be replaced by \
My code leads to the following exception:
java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at java.lang.String.charAt(String.java:444)
at java.util.regex.Matcher.appendReplacement(Matcher.java:551)
This is my code:
....
Pattern p = Pattern.compile("\\\\");
Matcher m = p.matcher(s);
StringBuffer sb = new StringBuffer();
boolean result = m.find();
while(result) {
m.appendReplacement(sb, "\\");
result = m.find();
}
m.appendTail(sb);
System.out.println(sb.toString());
....
Any idea?
Thanks,
Stephan
I have a problem with java.regex. In a given String \\ has to be replaced by \
My code leads to the following exception:
java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at java.lang.String.charAt(String.java:444)
at java.util.regex.Matcher.appendReplacement(Matcher.java:551)
This is my code:
....
Pattern p = Pattern.compile("\\\\");
Matcher m = p.matcher(s);
StringBuffer sb = new StringBuffer();
boolean result = m.find();
while(result) {
m.appendReplacement(sb, "\\");
result = m.find();
}
m.appendTail(sb);
System.out.println(sb.toString());
....
Any idea?
Thanks,
Stephan