java.util.regex.Pattern#split is misspecified

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P3
    • None
    • Affects Version/s: 1.4.0
    • Component/s: 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)
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: