如何从Perl字符串中提取文件路径? [英] How can I extract a file path from a Perl string?
本文介绍了如何从Perl字符串中提取文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从该字符串中找到具有全路径的文件名
I want to find the file name with fullpath from this string
"[exec] /snschome/sns/ccyp/mb_ccsns/bb/cbil5/v85_8/amdocs/iamcust/bil/cl/business/handlers/ClReportsHandler.java:233: cannot resolve symbol"
我要提取
/snschome/sns/ccyp/mb_ccsns/bb/cbil5/v85_8/amdocs/iamcust/bil/cl/business/handlers/ClReportsHandler.java
我正在Perl中尝试此操作
and I am trying this in Perl
$_=$string_from_to_match
my @extract_file=split(/.*(\/.*)\:.*/);
print $extract_file[1],"\n";`
但是我得到以下输出:
/ClReportsHandler.java:233:
它与最后一个/
和最后一个:
相匹配.如何将其更改为第一个/
和第一个:
?
It is matching the last /
and the last :
. How can I change it to first /
and first :
?
推荐答案
在这种情况下,粘性和伸展性"很有用.您知道,左边是[exec]
,后跟空格,右边是冒号,后跟行号.您想要介于两者之间的内容:
This is a case where "tacking and stretching" is useful. You know that [exec]
followed by whitespace is on the left and colon followed by a line number is on the right. You want what's in between:
#! /usr/bin/perl
use warnings;
use strict;
$_ = "[exec] /snschome/sns/ccyp/mb_ccsns/bb/cbil5/v85_8/amdocs/iamcust/bil/cl/business/handlers/ClReportsHandler.java:233: cannot resolve symbol";
if (/\[exec\]\s*(.+?):\d+/) {
print $1, "\n";
}
这篇关于如何从Perl字符串中提取文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文