Bug 53017 - Invalid escape sequence reported for valid regex escapes
Summary: Invalid escape sequence reported for valid regex escapes
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.0 M8   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-02-24 21:44 EST by Sameer Ajmani CLA
Modified: 2004-03-04 06:35 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sameer Ajmani CLA 2004-02-24 21:44:43 EST
This should replace all spaces in s with colons, and save the result in t:
String s = "a b c";
String t = s.replaceAll("\s", ":");

Eclipse does not allow this to build, reporting:
Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\)

Or is this a Java compiler error?

String.replaceAll, replaceFirst, split, and java.util.regex.Pattern.compile all 
use special escape sequence like \s to denote character classes; these are 
unusable with this bug.

Workaround: use the explicit character class, e.g., "[ \t\n\f\r]" instead 
of "\s".

Desired fix: make "Use of non-standard character class" a Style or Advanced 
option in the Java compiler properties dialog, with the standard 
Ignore/Warning/Error choices.  Perhaps suppress this complaint automatically 
for methods known to use regex escapes.
Comment 1 John Wiegand CLA 2004-02-25 19:33:16 EST
Compiler behavior looks correct.

Rewrite the snippet as follows: 

String t = s.replaceAll("\\s", ":");
Comment 2 Jerome Lanneluc CLA 2004-03-04 06:35:04 EST
Compiler behavior is ok. Please rewrite your code as suggested by John. 

Closing.