如何在 Perl 中搜索某个单词后的任意数字

发布于 2024-12-20 21:25:26 字数 2841 浏览 0 评论 0原文

Changeset: 40042
User: xyz
Date: Friday, July 29, 2011 9:54:52 PM

评论:

[I#1326920] RINS 参考数据维护开发已完成。添加了 RINDefinition、RINEquivalence 和 RINObligati

项目:

edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/application/common/ICTSDatabaseObjectMaps.java
edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/apps/admin/application/client/controller/MainController.java
edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/apps/admin/control/common/AdminCache.java
edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/apps/admin/control/common/AdminManager.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/_RINDefinition.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/_RINEquivalence.java


Changeset: 40043
User: xyzx
Date: Friday, July 29, 2011 9:54:52 PM

注释:

[I#1326920] RINS 参考数据维护开发已完成。添加了 RINDefinition、RINEquivalence 和 RINObligati

项目:

add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/_RINObligation.java
edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/Commodity.java
edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/CommodityType.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/RINDefinition.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/RINEquivalence.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/RINObligation.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/maps/RINDefinitionMap.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/maps/RINDefinitionMap.xml
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/maps/RINEquivalenceMap.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/maps/RINEquivalenceMap.xml
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/maps/RINObligationMap.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/maps/RINObligationMap.xml
edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/trade/TradeLocalizedResources.java

签入 注意:

Code Reviewer:
Performance Reviewer:
Security Reviewer:

以上行位于一个数组中。我想逐行阅读它,如果任何行包含 Changeset: 则获取 Changeset 旁边的数字: 请建议我如何做到这一点。

提前致谢。

来自OP评论的代码:

foreach(@loginfo){
    #print "$_\n";
    @rev = $_=~/^C(\d{1,})/g;
    #print "....@rev\n";
    push(@rev_value,@rev);
    print @rev_value,"\n";
}
Changeset: 40042
User: xyz
Date: Friday, July 29, 2011 9:54:52 PM

Comment:

[I#1326920] RINS Reference Data Maintenance Development completed. Added RINDefinition,RINEquivalence and RINObligati

Items:

edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/application/common/ICTSDatabaseObjectMaps.java
edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/apps/admin/application/client/controller/MainController.java
edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/apps/admin/control/common/AdminCache.java
edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/apps/admin/control/common/AdminManager.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/_RINDefinition.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/_RINEquivalence.java


Changeset: 40043
User: xyzx
Date: Friday, July 29, 2011 9:54:52 PM

Comment:

[I#1326920] RINS Reference Data Maintenance Development completed. Added RINDefinition,RINEquivalence and RINObligati

Items:

add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/_RINObligation.java
edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/Commodity.java
edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/CommodityType.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/RINDefinition.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/RINEquivalence.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/RINObligation.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/maps/RINDefinitionMap.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/maps/RINDefinitionMap.xml
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/maps/RINEquivalenceMap.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/maps/RINEquivalenceMap.xml
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/maps/RINObligationMap.java
add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/maps/RINObligationMap.xml
edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/trade/TradeLocalizedResources.java

Check-in Notes:

Code Reviewer:
Performance Reviewer:
Security Reviewer:

The above lines are in one array. I want to read it line by line and if any line contains Changeset: then get the number next to Changeset:
Please suggest me how to do this.

Thanks in advance.

Code from OP's comment:

foreach(@loginfo){
    #print "$_\n";
    @rev = $_=~/^C(\d{1,})/g;
    #print "....@rev\n";
    push(@rev_value,@rev);
    print @rev_value,"\n";
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟花肆意 2024-12-27 21:25:26

只需使用 regexp - man perlre

foreach my $l(@lines) {
    if ($l =~ /Changeset:\s+?(\d+)/) {
         print "$1\n";
    }
}

编辑:

$input = <<EOL;
  edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/application/common/ICTSDatabaseObjectMaps.java
  edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/apps/admin/application/client/controller/MainController.java
  edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/apps/admin/control/common/AdminCache.java
  edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/apps/admin/control/common/AdminManager.java
  add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/_RINDefinition.java
  add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/_RINEquivalence.java
`Changeset: 40043`
  edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/apps/admin/control/common/AdminCache.java

`Changeset: 4294967295`
  add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/_RINEquivalence.java

`Changeset: 42949672951289312789398123987123`
EOL
foreach my $l(split(/\n/,$input)) {
    if ($l =~ /Changeset:\s+?(\d+)/) {
         print "number $1\n";
    }
}

输出

number 40043
number 4294967295
number 42949672951289312789398123987123

just use regexp - man perlre

foreach my $l(@lines) {
    if ($l =~ /Changeset:\s+?(\d+)/) {
         print "$1\n";
    }
}

EDIT:

$input = <<EOL;
  edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/application/common/ICTSDatabaseObjectMaps.java
  edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/apps/admin/application/client/controller/MainController.java
  edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/apps/admin/control/common/AdminCache.java
  edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/apps/admin/control/common/AdminManager.java
  add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/_RINDefinition.java
  add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/_RINEquivalence.java
`Changeset: 40043`
  edit $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/apps/admin/control/common/AdminCache.java

`Changeset: 4294967295`
  add  $/S/B/F_RINS/Java/V3/ICTS/src/com/tradecapture/icts/model/commoditymarket/_RINEquivalence.java

`Changeset: 42949672951289312789398123987123`
EOL
foreach my $l(split(/\n/,$input)) {
    if ($l =~ /Changeset:\s+?(\d+)/) {
         print "number $1\n";
    }
}

outputs

number 40043
number 4294967295
number 42949672951289312789398123987123
不再让梦枯萎 2024-12-27 21:25:26

如果数组中包含所有行,则可以使用 map

use v5.10;
my @lines = map /^Changeset:\s*(\d+)/g, @array;
say for @lines;

如果您用文件句柄替换数组,例如 <$fh> (或任何列表),也可以工作。

If you have all the lines in an array, you can use map

use v5.10;
my @lines = map /^Changeset:\s*(\d+)/g, @array;
say for @lines;

Also works if you replace the array with a filehandle, e.g. <$fh> (or any list, for that matter).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文