Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4497915

java.util.regex.Pattern#split is misspecified

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.0
    • core-libs
    • generic
    • generic



      Name: nt126004 Date: 08/29/2001


      The specification of the Pattern#split limit argument doesn't match Perl and
      misses the whole point of the limit. According to
      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
      whole 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.
      (Review ID: 130770)
      ======================================================================

            mmcclosksunw Michael Mccloskey (Inactive)
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: