Regex 匹配复杂字符串或行的正则表达式

Regex 匹配复杂字符串或行的正则表达式,regex,maven-plugin,header-files,Regex,Maven Plugin,Header Files,我必须检查一些java类代码的头部分,我正在使用maven license plugin,我必须在公共头文件(文本)中指定一个正则表达式,以允许这样的行: 2013 andrea版权所有的部分 或 版权所有2008-2009 Company,Inc.保留所有权利。 你能帮我吗 标题的模板为: ==================== DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. Copyright 2008-2009 comp

我必须检查一些java类代码的头部分,我正在使用maven license plugin,我必须在公共头文件(文本)中指定一个正则表达式,以允许这样的行:

2013 andrea版权所有的部分

版权所有2008-2009 Company,Inc.保留所有权利。

你能帮我吗

标题的模板为:

====================
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

Copyright 2008-2009 company, Inc. All rights reserved.

The contents of this file are subject to the terms of the Common Development 
and Distribution License("CDDL") (the "License"). You may not use this file 
except in compliance with the License.

You can obtain a copy of the License at https://xxx.yy.com/licenses/CDDL
See the License for the specific language governing permissions and limitations 
under the License. 

When distributing the Covered Code, include this CDDL Header Notice in each file
and include the License file at https://xxx.yy.com/licenses/CDDL.
If applicable, add the following below this CDDL Header, with the fields 
enclosed by brackets [] replaced by your own identifying information: 
"Portions Copyrighted [year] [name of copyright owner]"
====================
试试这个:

^.*Copyright(ed)?\s+\d+(-\d+)?.+$

你能说说规则吗?例如,哪个字符不会改变,哪个字符会改变?我必须能够识别发布的模板,以及文件末尾的一行,比如2013年andrea受版权保护的部分,以及第一次版权之后的一行:版权2008-2009公司,Inc.保留所有权利。此模板的唯一更改是这两个可能的添加项,剩下的全部文本都是相同的。如果存在
©
而不是版权?或者用另一种语言
droit d'auteur
?这种情况是不允许的,因为我已经有了带有标题的文件,我阅读了所有的文件,文件之间的唯一区别是我发布的文件,如果我必须检查是否有空行?我认为你的建议非常接近正确答案,但是maven插件仍然不起作用,可能在“部分受版权保护…”之前无法识别文件末尾可能出现的空白行。我用neatbeans做了一些测试,您的表达几乎完美,但与此不符:“版权(c)2011-2013 ForgeRock AS.All Rights Reserved”感谢@Tim.Tang。解决方案是:^.*版权(ed)?(\s(c) )\s+\d+(\d+)+$