-
Bug
-
Resolution: Fixed
-
P2
-
1.4.0
-
None
-
beta3
-
generic
-
generic
-
Verified
Date: Tue, 28 Aug 2001 15:55:10 -0700
From: Jim Balter <###@###.###>
The Java folks decided to "borrow" the split function from Perl.
Unfortunately, their appears to have been some misunderstanding of
the Perl functionality. According to the Java 1.4 documentation at
http://java.sun.com/j2se/1.4/docs/api/java/util/regex/Pattern.html
The input "boo:and:foo", for example, yields the following results with these parameters:
Regex Limit Result
: 2 { "boo", "and" }
But this is *not* what Perl's split does, and misses the
point of the "limit" argument. The perl program
perl -le 'print join(" ", split(":", "boo:and:foo", 2))'
prints
boo and:foo
*not*
boo and
The point of the "limit" argument is to limit the number
of times the pattern is applied, so that, e.g., only the
first ':' is treated as a separator. But the Java version
doesn't provide this functionality, and this disparity will
cause confusion for people who are exposed to both languages.
Thanks for your time and attention.
From: Jim Balter <###@###.###>
The Java folks decided to "borrow" the split function from Perl.
Unfortunately, their appears to have been some misunderstanding of
the Perl functionality. According to the Java 1.4 documentation at
http://java.sun.com/j2se/1.4/docs/api/java/util/regex/Pattern.html
The input "boo:and:foo", for example, yields the following results with these parameters:
Regex Limit Result
: 2 { "boo", "and" }
But this is *not* what Perl's split does, and misses the
point of the "limit" argument. The perl program
perl -le 'print join(" ", split(":", "boo:and:foo", 2))'
prints
boo and:foo
*not*
boo and
The point of the "limit" argument is to limit the number
of times the pattern is applied, so that, e.g., only the
first ':' is treated as a separator. But the Java version
doesn't provide this functionality, and this disparity will
cause confusion for people who are exposed to both languages.
Thanks for your time and attention.
- duplicates
-
JDK-4497915 java.util.regex.Pattern#split is misspecified
-
- Closed
-