java 正则 排除,Checkstyle-如何使用正则表达式排除以'Impl.java'结尾的文件,但不排除任何文件?...

I have been thinking some time about this problem.

I have a huge Maven multi module project and using build-tools I share a custom set of rules for all modules (no problem around here).

The problem comes when I want to apply one rule to just one set of files in just one of the modules. By using checkstyle suppressions file I can easyly exclude all files that I don't want the rule to apply, but it has its limitations. Lets put this into an example:

Files:

a/b/c/d/FileImpl.java

a/b/c/d/File.java

a/b/c/d/e/FileImpl.java

a/b/c/FileImpl.java

...

What regex would you write that assures you that all files (including future files that may be introduced) get excluded but just the ones that end with Impl.java under package a.b.c.d? in terms of regex, it has to be a regex that matches anything but the file ending I want.

It would be easyer if I could just set an "includes" referring only to the set of files to apply the rule to, but as far as I know that's not possible. It has to be using suppressions, so that it suppresses all files but the ones I want.

I have tried using capturing groups, lookahead and lookbehind but had no success at all.

Any ideas?

解决方案

Found the right solution to the not so clear question, hope it helps anyone interested.

Regex Goal --> match any chain but the ones that match the internal regex.

Regex --> ^((?!d/\w+Impl\.java).)*$

Using negative lookahead and the template: ^((?!regexp).)*$

Thanks for the support!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值