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

Change language specification for easier writing of Regular Expressions

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Other
    • Icon: P4 P4
    • None
    • None
    • specification

      Name: rmT116609 Date: 08/26/2004


      A DESCRIPTION OF THE REQUEST :
      The intention of this proposed change is to make writing regular expressions more straightforward and more Perl-like. Writing a regular expression in Java is, besides thinking about logic, also about adding a lot of backslashes.

      Instead of the double quote I suggest to use the back quote (what's in a name), and also a RegexString object that extends the String object.
      Examples:
      "\\(.*?\\)" .equals(`\(.*?\)`);
      `\(hello\)`.equals("\\(hello\\)");
      Pattern p = Pattern.compile(`\s+\d+`);

      JUSTIFICATION :
      Although escaping special characters with a backslash is in the Java Language Specification, the result is that regular expressions become less readable and maintainable. To get rid of the extra backslashes I suggest to create this new String-like object that handles backslashes more gracefully.
      (Incident Review ID: 237231)
      ======================================================================

            abuckley Alex Buckley
            abuckley Alex Buckley
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: