agnul
agnul

Reputation: 13058

IntelliJ says \b (backspace) is an illegal escape sequence inside a string literal. Why?

I have this piece of code

private static final Pattern controlChars = Pattern.compile(
        "[\u0001-\u0008\u000B\u000C\u000E-\u001F\u007F]");

and IntelliJ idea (2016.3) puts a red squiggle under \u0008 saying it's an illegal/unsupported escape sequence. Changing it to any of \b, \010 or \x08 has no effect.

What I don't get is that the code builds and runs without a problem. Any idea what's the issue?

Upvotes: 4

Views: 2702

Answers (1)

Bas Leijdekkers
Bas Leijdekkers

Reputation: 26482

This is a bug in the RegExp support. It is fixed in IntelliJ IDEA 2017.1 Public Preview.

You can remove the (harmless) error by positioning the text cursor on the error, typing Alt+Enter and invoking Un-inject Language/Reference. However this will also disable all other RegExp features on this literal.

Upvotes: 6

Related Questions