2013-06-28 69 views
0

我要檢查一些java類代碼的頭部分,我使用的是maven-license-plugin,並且我必須在常見頭文件(文本)文件中指定常規表達允許這樣的臺詞:正則表達式來匹配複雜的字符串或行

Portions Copyrighted 2013 andrea

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

你能幫助我嗎?

頭的模板是​​:

==================== 
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]" 
==================== 
+0

你可以說說規則嗎?比如哪個字符沒有改變,哪些字符會改變? –

+0

,我必須能夠識別所發佈的模板以及文件末尾的一行,例如部分版權所有2013 andrea以及第一版權之後的附加行:Copyright 2008-2009 Company,Inc.保留所有權利。 – andPat

+0

對這個模板的唯一更改是這兩個可能的添加,整個剩餘的文本是相同的 – andPat

回答

1

試試這個:

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

以及是否需要檢查是否存在空白行? – andPat

+0

我認爲你的建議非常接近正確的答案,但maven插件仍然無法正常工作,也許在「部分版權保護......」之前無法識別文件末尾可能出現的空行...... – andPat

+0

我用neatbeans做了一些測試,你的表情幾乎是完美的,但不符合這種情況:「Copyright(c)2011-2013 ForgeRock AS。All Rights Reserved」 – andPat