JDK-8061405 : Change language specification for easier writing of Regular Expressions
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Priority: P4
  • Status: Closed
  • Resolution: Other
  • Submitted: 2004-08-26
  • Updated: 2014-10-17
  • Resolved: 2014-10-17
Related Reports
Relates :  
Relates :  
Relates :  
Description
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) 
======================================================================

Comments
The 'specification' component of the Java Bug System is for reporting technical errors and ambiguities in the text of The Java Language Specification and The JVM Specification. It is not the venue to propose new features in the Java language or JVM. Ongoing feature development is carried out in OpenJDK (http://openjdk.java.net/jeps/); corresponding enhancements to The Java Language Specification and The JVM Specification are managed through the Java Community Process (http://jcp.org/).
17-10-2014

EVALUATION One of numerous requests for easier handling of literals.
17-11-2006