-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
beta2
-
x86, sparc
-
solaris_7, windows_2000
-
Verified
Problem with ^ and Pattern.MUTLILINE with replaceAll()....
//////////////////////////////////////////////////////////////////////
import java.util.regex.*;
public class test1 {
public static void main(String [] args) {
Pattern p = Pattern.compile("^", Pattern.MULTILINE);
Matcher m = p.matcher("this is some text");
System.out.println(m.replaceAll("X"));
// prints "XtXhXiXsX XiXsX XsXoXmXeX XtXeXxXtX"
// expected "Xthis is some text"
}
}
//////////////////////////////////////////////////////////////////////
If you remove Pattern.MULTILINE.........
//////////////////////////////////////////////////////////////////////
import java.util.regex.*;
public class test2 {
public static void main(String [] args) {
Pattern p = Pattern.compile("^");
Matcher m = p.matcher("this is some text");
System.out.println(m.replaceAll("X"));
// raises: StringIndexOutOfBoundsException
// expected "Xthis is some text"
}
}
Name: bsC130419 Date: 07/23/2001
C:\java>java -version
java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)
C:\java>
Here's the test program...
import java.util.regex.*;
public class Foo {
public static void main(String[] args) {
System.out.println("Match test...");
Pattern p = Pattern.compile("(^.*$){4,}", Pattern.MULTILINE);
Matcher m = p.matcher("aaaa\nbbbb\n");
while (m.find()) {
System.out.println("Match (" + m.start() + "," + m.end() + "): '"
+ m.group() + "'");
}
}
}
And here's the output...
C:\java>java Foo
Match test...
Match (0,10): 'aaaa
bbbb
'
Match (10,10): ''
C:\java>
I would expect that since the input has fewer than than 4 lines, there should
be no matches. The last match is really bizarre. It's the same with \r\n as
the line terminator as well.
(Review ID: 128589)
======================================================================
//////////////////////////////////////////////////////////////////////
import java.util.regex.*;
public class test1 {
public static void main(String [] args) {
Pattern p = Pattern.compile("^", Pattern.MULTILINE);
Matcher m = p.matcher("this is some text");
System.out.println(m.replaceAll("X"));
// prints "XtXhXiXsX XiXsX XsXoXmXeX XtXeXxXtX"
// expected "Xthis is some text"
}
}
//////////////////////////////////////////////////////////////////////
If you remove Pattern.MULTILINE.........
//////////////////////////////////////////////////////////////////////
import java.util.regex.*;
public class test2 {
public static void main(String [] args) {
Pattern p = Pattern.compile("^");
Matcher m = p.matcher("this is some text");
System.out.println(m.replaceAll("X"));
// raises: StringIndexOutOfBoundsException
// expected "Xthis is some text"
}
}
Name: bsC130419 Date: 07/23/2001
C:\java>java -version
java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)
C:\java>
Here's the test program...
import java.util.regex.*;
public class Foo {
public static void main(String[] args) {
System.out.println("Match test...");
Pattern p = Pattern.compile("(^.*$){4,}", Pattern.MULTILINE);
Matcher m = p.matcher("aaaa\nbbbb\n");
while (m.find()) {
System.out.println("Match (" + m.start() + "," + m.end() + "): '"
+ m.group() + "'");
}
}
}
And here's the output...
C:\java>java Foo
Match test...
Match (0,10): 'aaaa
bbbb
'
Match (10,10): ''
C:\java>
I would expect that since the input has fewer than than 4 lines, there should
be no matches. The last match is really bizarre. It's the same with \r\n as
the line terminator as well.
(Review ID: 128589)
======================================================================