IntelliLang question

IntelliLang flags the following regexp with a warning

"(.) -> (.)(
[[:]+:[:]+
])?
((.+)
)"

specifically the
] closing square bracket is flagged as redundant escape as shown in the screenshot.

Is this correct ? It does not flag the opening
[ as redundant, so why the closing one ?



Attachment(s):
Clipboard01.jpg
2 comments
Comment actions Permalink

Hello Thibaut,

IntelliLang flags the following regexp with a warning

"(.) -> (.)(
[[:]+:[:]+
])?
((.+)
)"

specifically the
] closing square bracket is flagged as redundant escape as shown in the screenshot.

Is this correct ? It does not flag the opening
[ as redundant, so why the closing one ?


Yes, this is correct, although I agree it's a bit confusing. The opening '[' is a reserved character
that indicates a character class and has to be escaped when used literally. However, a single ']'
outside a character class has no special meaning, and thus doesn't need to be escaped. Here's the proof:

final boolean b1 = Pattern.compile("]").matcher("]").matches();
final boolean b2 = Pattern.compile("
]").matcher("]").matches();
System.out.println("b1 = " + b1);
System.out.println("b1 = " + b2);

Both patterns compile fine and b1 as well as b2 will be true.

Maybe it should not flag this at all because it seems that people like to escape it nonetheless for
consistency and a more symmetric look. (And which would fix the actual bug in "[abc
]]" ;))

Sascha

0
Comment actions Permalink

quite odd :) thx

0

Please sign in to leave a comment.