Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何用perlre打印出matached字符串?_Regex_Perl - Fatal编程技术网

Regex 如何用perlre打印出matached字符串?

Regex 如何用perlre打印出matached字符串?,regex,perl,Regex,Perl,Perlre(Perl正则表达式)用于搜索/替换复杂的XML结构,例如 perl -0777 -pe 's/<ac:structured-macro ac:macro-id="[a-z0-9\-]+" ac:name="gadget" ac:schema-version="1"><ac:parameter ac:name="preferences">.*?selectedIssueKey=([A-Z\-0-9]+).*?(<\/ac:parameter>)&l

Perlre(Perl正则表达式)用于搜索/替换复杂的XML结构,例如

perl -0777 -pe 's/<ac:structured-macro ac:macro-id="[a-z0-9\-]+" ac:name="gadget" ac:schema-version="1"><ac:parameter ac:name="preferences">.*?selectedIssueKey=([A-Z\-0-9]+).*?(<\/ac:parameter>)<ac:parameter ac:name="url">https:\/\/rcrs.rbinternational.corp\/issue\/rest\/gadgets\/1.0\/g\/com.pyxis.greenhopper.jira:greenhopper-card-view-gadget\/gadgets\/greenhopper-card-view.xml<\/ac:parameter>.*?(<\/ac:structured-macro>)/<ac:structured-macro ac:name="jira" ac:schema-version="1"><ac:parameter ac:name="server">RCRS Issue Tracking<\/ac:parameter><ac:parameter ac:name="columns">key,type,assignee,status,nwu model developer,nwu model reviewer,nwu model owner,nwu head rr\/b2\/cro,ho validation owner,ho pi\/micro country manager,ho responsible signee<\/ac:parameter><ac:parameter ac:name="maximumIssues">20<\/ac:parameter><ac:parameter ac:name="jqlQuery">key = \1 <\/ac:parameter><ac:parameter ac:name="serverId">d64129aa-b1e8-3584-8953-2bd89c3e515c<\/ac:parameter><\/ac:structured-macro>/igs' macro
perl-0777-pe's/*?selectedIssueKey=([A-Z \-0-9]+).*(),总行验证负责人、总行pi\/微观国家经理、总行负责人签名20Key=\1 d64129aa-b1e8-3584-8953-2bd89c3e515c/igs宏
当前搜索模式与预期不匹配。显然,搜索模式跨越的字符串比预期的多。是否可以打印出每个匹配的字符串以进行调试

use re 'debug'
要调试regex,请在此处阅读更多有关它的信息

要调试regex,请在此处阅读更多有关它的信息

要调试regex,请在此处阅读更多有关它的信息


要调试正则表达式,请在此处阅读有关它的更多信息

为此使用CPAN模块。也许可以帮你省去一些头痛


但是,如果您仍然希望使用regex来完成此任务,我建议您在脚本中展开regex,并使用上面提到的调试器逐步完成它

为此使用CPAN模块。也许可以帮你省去一些头痛


但是,如果您仍然希望使用regex来完成此任务,我建议您在脚本中展开regex,并使用上面提到的调试器逐步完成它

为此使用CPAN模块。也许可以帮你省去一些头痛


但是,如果您仍然希望使用regex来完成此任务,我建议您在脚本中展开regex,并使用上面提到的调试器逐步完成它

为此使用CPAN模块。也许可以帮你省去一些头痛


但是,如果您仍然希望使用regex来完成此任务,我建议您在脚本中展开regex,并使用上面提到的调试器逐步完成它

您可以使用
重新“调试”打开
regex
的调试。然而,这将是错误的做法。这里的问题不是你的正则表达式错了,而是
regex
从根本上说是
XML
解析的错误工具。(撇开这一点不谈——您的行太长了,这样使用内联是不明智的!)

给出您的示例—看起来您正试图提取单个值(selectedIssueKey)并将其插入到新的XML blob中

这可以通过解析器轻松地完成,例如。我不能给出一个精确的例子,因为我需要查看您的XML结构(或者至少是没有通配符的子集)

但类似的东西可用于从某些XML中提取值:

#!/usr/bin/perl
use strict;
use warnings;
use XML::Twig; 

my $twig = XML::Twig -> parse ( \*DATA );
my $selectedIssueKey = $twig -> findnodes ( '//ac:parameter/pref', 0) -> att('selectedIssueKey');
print $selectedIssueKey;
从以下内容中提取属性“selectedIssueKey”的值:

<ac:structured-macro ac:macro-id="test" ac:name="gadget" ac:schema-version="1">
  <ac:parameter ac:name="preferences">
      <pref selectedIssueKey="anothertest" />
  </ac:parameter>
  <ac:parameter ac:name="url">https://rcrs.rbinternational.corp/issue/rest/gadgets/1.0/g/com.pyxis.greenhopper.jira:greenhopper-card-view-gadget/gadgets/greenhopper-card-view.xml</ac:parameter>
</ac:structured-macro>

(不过,使用一个完整的XML片段来实现这一点可能更容易,只需替换yo uwant中的位即可)

您可以使用
重新“调试”打开
regex
的调试。然而,这将是错误的做法。这里的问题不是你的正则表达式错了,而是
regex
从根本上说是
XML
解析的错误工具。(撇开这一点不谈——您的行太长了,这样使用内联是不明智的!)

给出您的示例—看起来您正试图提取单个值(selectedIssueKey)并将其插入到新的XML blob中

这可以通过解析器轻松地完成,例如。我不能给出一个精确的例子,因为我需要查看您的XML结构(或者至少是没有通配符的子集)

但类似的东西可用于从某些XML中提取值:

#!/usr/bin/perl
use strict;
use warnings;
use XML::Twig; 

my $twig = XML::Twig -> parse ( \*DATA );
my $selectedIssueKey = $twig -> findnodes ( '//ac:parameter/pref', 0) -> att('selectedIssueKey');
print $selectedIssueKey;
从以下内容中提取属性“selectedIssueKey”的值:

<ac:structured-macro ac:macro-id="test" ac:name="gadget" ac:schema-version="1">
  <ac:parameter ac:name="preferences">
      <pref selectedIssueKey="anothertest" />
  </ac:parameter>
  <ac:parameter ac:name="url">https://rcrs.rbinternational.corp/issue/rest/gadgets/1.0/g/com.pyxis.greenhopper.jira:greenhopper-card-view-gadget/gadgets/greenhopper-card-view.xml</ac:parameter>
</ac:structured-macro>

(不过,使用一个完整的XML片段来实现这一点可能更容易,只需替换yo uwant中的位即可)

您可以使用
重新“调试”打开
regex
的调试。然而,这将是错误的做法。这里的问题不是你的正则表达式错了,而是
regex
从根本上说是
XML
解析的错误工具。(撇开这一点不谈——您的行太长了,这样使用内联是不明智的!)

给出您的示例—看起来您正试图提取单个值(selectedIssueKey)并将其插入到新的XML blob中

这可以通过解析器轻松地完成,例如。我不能给出一个精确的例子,因为我需要查看您的XML结构(或者至少是没有通配符的子集)

但类似的东西可用于从某些XML中提取值:

#!/usr/bin/perl
use strict;
use warnings;
use XML::Twig; 

my $twig = XML::Twig -> parse ( \*DATA );
my $selectedIssueKey = $twig -> findnodes ( '//ac:parameter/pref', 0) -> att('selectedIssueKey');
print $selectedIssueKey;
从以下内容中提取属性“selectedIssueKey”的值:

<ac:structured-macro ac:macro-id="test" ac:name="gadget" ac:schema-version="1">
  <ac:parameter ac:name="preferences">
      <pref selectedIssueKey="anothertest" />
  </ac:parameter>
  <ac:parameter ac:name="url">https://rcrs.rbinternational.corp/issue/rest/gadgets/1.0/g/com.pyxis.greenhopper.jira:greenhopper-card-view-gadget/gadgets/greenhopper-card-view.xml</ac:parameter>
</ac:structured-macro>

(不过,使用一个完整的XML片段来实现这一点可能更容易,只需替换yo uwant中的位即可)

您可以使用
重新“调试”打开
regex
的调试。然而,这将是错误的做法。这里的问题不是你的正则表达式错了,而是
regex
从根本上说是
XML
解析的错误工具。(撇开这一点不谈——您的行太长了,这样使用内联是不明智的!)

给出您的示例—看起来您正试图提取单个值(selectedIssueKey)并将其插入到新的XML blob中

这可以通过解析器轻松地完成,例如。我不能给出一个精确的例子,因为我需要查看您的XML结构(或者至少是没有通配符的子集)

但类似的东西可用于从某些XML中提取值:

#!/usr/bin/perl
use strict;
use warnings;
use XML::Twig; 

my $twig = XML::Twig -> parse ( \*DATA );
my $selectedIssueKey = $twig -> findnodes ( '//ac:parameter/pref', 0) -> att('selectedIssueKey');
print $selectedIssueKey;
从以下内容中提取属性“selectedIssueKey”的值:

<ac:structured-macro ac:macro-id="test" ac:name="gadget" ac:schema-version="1">
  <ac:parameter ac:name="preferences">
      <pref selectedIssueKey="anothertest" />
  </ac:parameter>
  <ac:parameter ac:name="url">https://rcrs.rbinternational.corp/issue/rest/gadgets/1.0/g/com.pyxis.greenhopper.jira:greenhopper-card-view-gadget/gadgets/greenhopper-card-view.xml</ac:parameter>
</ac:structured-macro>

(不过,使用一个完整的XML片段来实现这一点可能更容易,只需替换yo uwant中的位即可)

使用XML解析器解析XML<代码>正则表达式
对于这项工作来说是一个糟糕的工具。发布一个XML片段和您试图提取的内容,我们可以给您一个示例。使用XML解析器解析XML
regex
是一个