I'm trying to make a rule to catch invalid characteres. Those are & < > /* ' " --
I already managed to "catch" all the symbols except the /*
My code is:
rule "Invalid Chars"
when
c : Class ( field matches ".*[&<>'\"].*|.*(--).*" )
then
// DO SOMETHING
end
My regex is below. But when I try to add the /* symbol. I get this regex
.*[&<>'\"].*|.*(--).*|.*(\/\*).*
But when I try to run I get this error:
line 1:28 no viable alternative at character '*' line 1:33 mismatched character '' expecting '"' java.lang.IllegalStateException: ### errors ### [Error: illegal escape sequence: *]~
How to "catch" all these invalid characters?
Here's minimal Test with * escaped but / not:
public static void main(String[] args) {
if("Hallo /* Test ".matches(".*[&<>'\"].*|.*(--).*|.*(/\\*).*")) {
System.out.println("ILLEGAL");
}
}