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

String.replaceAll() not giving expected result.

XMLWordPrintable

    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      OS: Windows 10 Pro
      java: Java SE Development Kit 8u211 for Windows x64

      A DESCRIPTION OF THE PROBLEM :
      The replaceAll method of a String object produces unexpected results.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
                     String sourceText = "ab";
      String regex = "ab";
      String replacement = "\\\"";
      String result = sourceText.replaceAll(regex, replacement);
      if (!result.equals(replacement)) {
      throw new RuntimeException("Replacement result does not meet expectations");
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The variable 'result' is equal to the variable 'replacement'
      ACTUAL -
      The variable 'result' is not equal to the variable 'replacement'

      FREQUENCY : always


            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: