如何在checkstyle的RegexpHeader中指定带有换行符的可选正则表达式组?

Kar*_*ter 9 java regex checkstyle maven

我在例如,在模块中指定()?包含换行符(\n)的正则表达式组()时遇到问题RegexpHeadermaven-checkstyle-plugin

<module name="Checker">
    <module name="RegexpHeader">
        <property
            name="header"
            value="a\nb"/>
        <property name="fileExtensions" value="java"/>
    </module>
</module>
Run Code Online (Sandbox Code Playgroud)

哪里value="a(\nc)?b"失败有错误Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (check_style) on project document-scanner: Failed during checkstyle configuration: cannot initialize module RegexpHeader - Cannot set property 'header' to 'a(\nc)?b' in module RegexpHeader: InvocationTargetException: line 1 in header specification is not a regular expression -> [Help 1].

根据RegexpHeader文档

各个标题行必须用字符串"\n"分隔

这解释了正则表达式导致错误,但它阻止了使用包含换行符的可选组的正则表达式的规范.此例的示例也未指定.

解决方案不起作用:

value="/\*a&#10;cb\*/\n" 火柴

/*a
cb*/
bla bla
Run Code Online (Sandbox Code Playgroud)

所以它似乎是正则表达式控制字符(()?)导致麻烦.

我正在使用maven-checkstyle-plugin2.17和Java 7.

我创建了https://github.com/krichter722/maven-checkstyle-plugin-multiline以便于调查.

Boh*_*ian 1

尝试多行模式,其中^并匹配每行$的开始/结束:

(?m)a($\s+^c)?b
Run Code Online (Sandbox Code Playgroud)

您可能需要尝试一下如何编写反斜杠代码。