What regular expression to find a string that does not contain a substring?

I am working on a simple tool for checking Java coding guidelines for a project. One of these recommendations is to make sure that there is no variable declared as "private static ...", only "private static final ..." is allowed.

I am wondering how I can get this result. I wrote this:

pattern  = "private\\\s*static\\\s*(?!final)";

But it does not work. How can I get only entries without the keyword "final"?

Thanks, Med.

+3
source share
5 answers

That should work, yes. You might want to move the second white space in the viewport:

pattern = "private\\s*static(?!\\s*final)";
+3
source

, . - , "" (, ) (, "" ).

IMO, . PMD. PMD , AST. .., , .

+2

\s +, , .

private\\s+static\\s+(?!final).+

. +, , , .

0

( , ). \\s+ \\s* , . privatestaticfoobar, , .

0

. , . .

0

Source: https://habr.com/ru/post/1756488/


All Articles