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

overload replace method in String class to use regex

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • core-libs
    • generic
    • generic



      Name: bsC130419 Date: 06/04/2001


      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)

      Since Perl-style regular expressions are finally making their way into the SDK,
      and even into the String class with split (a function for which I'm very
      grateful :-), it would be very helpful to overload the replace method in the
      String class to use regular expressions as well. A proposed method signature:
      public String replace(String regex,String newText)
      The function would operate on a String and replace all matches of the given
      regex with the new text. The net result would be a function that works similar
      to Perl's substitute functions.
      If you're going to have regex, you might as well have substitution. That's half
      the usefulness of regular expressions. I'll code it, if you like.
      Another alternative would be to call the new method "substitute", as in Perl.
      I know the Matcher class has a replaceAll method, but it would be helpful to
      have it directly in String.
      (Review ID: 125778)
      ======================================================================

            iris Iris Clark
            bstrathesunw Bill Strathearn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: