0

我需要一个正则表达式来获取最后一次出现的 .java;[number] 或 java;NONE 和字符串结尾之间的文本。

这是我输入的文本示例:

user: ilian
branch: HEAD
changed files:
FlatFilePortfolioImportController.java;1.78
ConvertibleBondParser.java;1.52
OptionKnockedOutException.java;1.1.2.1
RebatePayoff.java;NONE

possible dead-lock. The suggested solution is to first create a TransactionContext and then lock AccountableDataFactory.IMPORT_LOCK and PositionManagerSQL

基本上我需要在提交结束时获得注释,这是在最后一个更改的文件之后,它可能以 1.52、1.1.2.1 或 NONE 之类的结尾。

4

3 回答 3

0
String regex = "\\.java;\\d+\\.\\d+(.+)";
Pattern p = Pattern.compile(regex, Pattern.DOTALL);
Matcher m = p.matcher(input);

if (m.find()) {
    System.out.println(m.group(1));
}
于 2013-06-27T16:00:09.717 回答
0

编辑 后的解决方案假设输入在一行中(原始帖子中的行仅是为了清楚起见,请参阅下面的 OP 评论)。

String input = "user: ilian branch: "
        + "HEAD changed files: "
        + "FlatFilePortfolioImportController.java;1.78 "
        + "ConvertibleBondParser.java;1.52 "
        + "possible dead-lock. The suggested solution is to first create a "
        + "TransactionContext and then lock AccountableDataFactory.IMPORT_LOCK "
        + "and PositionManagerSQL";
// checks last occurrence of java;x.xx, optional space(s), anything until end of input
Pattern pattern = Pattern.compile(".+java;[\\d\\.]+\\s+?(.+?)$");
Matcher matcher = pattern.matcher(input);
if (matcher.find()) {
    System.out.println(matcher.group(1));
}

输出:

possible dead-lock. The suggested solution is to first create a TransactionContext and then lock AccountableDataFactory.IMPORT_LOCK and PositionManagerSQL
于 2013-06-27T16:01:16.663 回答
0
String comment = mydata.replaceAll("(?s).*java;[0-9,.]+|.*java;NONE", "");
System.out.println(comment);

适用于所有文件结尾并正确打印。

于 2013-06-28T08:27:05.260 回答