首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在perlscript中使用RegEx提取两个标记之间的编码

如何在perlscript中使用RegEx提取两个标记之间的编码
EN

Stack Overflow用户
提问于 2022-11-17 18:14:23
回答 1查看 73关注 0票数 4

我想提取和之间的编码。请建议如何提取它们。

代码语言:javascript
复制
<ix:hidden>
<ix:nonNumeric contextRef="Duration_4_1_2021_To_3_31_2022_IlKaMcQ2N0C41UxW3xo4zg" name="dei:DocumentType" id="Tc_evMsUKdlCEyCZtbxEMZIxg_1_1">DEF 14A</ix:nonNumeric>
<ix:nonNumeric contextRef="Duration_4_1_2021_To_3_31_2022_IlKaMcQ2N0C41UxW3xo4zg" name="dei:AmendmentFlag" id="Tc_nHcapE52UUqrWD0pLkbdag_2_1">false</ix:nonNumeric>
<ix:nonNumeric contextRef="Duration_4_1_2021_To_3_31_2022_IlKaMcQ2N0C41UxW3xo4zg" name="dei:EntityRegistrantName" id="Tc_ZXMW19KSmk2TfvdhMCMr_A_3_1">Walter Hamscher Co Number One</ix:nonNumeric>
<ix:nonNumeric contextRef="Duration_4_1_2021_To_3_31_2022_IlKaMcQ2N0C41UxW3xo4zg" name="dei:EntityCentralIndexKey" id="Tc_MybzAywpbUCU3LEGZc_Ftg_4_1">0000990667</ix:nonNumeric>
</ix:hidden>
代码语言:javascript
复制
use strict;
use warnings;

my @ar_sp;
my $string;
my @ar_out;

# Source File 
my $src = 'iXBRL-Tagged_tm213138-13_def14a.htm';

# open source file for reading
open(FHR, '<', $src);
  
# Destination File
my $des = 'output.txt';

# Open new file to write
open(FHW, '>', $des);
  
  
print("Copying content from $src to $des\n");
@ar_sp = <FHR>;

# Copy data from one file to another.
foreach $string ( @ar_sp ) 
{
    if ($string =~ m/<ix:hidden>(.*?)<\/ix:hidden>/)
    {
        print "Yes" . "\n";
        $string =~ m/<ix:hidden>(.*?)<\/ix:hidden>/;
        print FHW $string;
    }
    
}

# Closing the filehandles
close(FHR);
close(FHW);
   
print "File content copied successfully!\n";

===========================================

Defined Regex not matched in the script
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-17 20:03:56

那里有很好的XML解析器。不要太差--重新发明轮子。

代码语言:javascript
复制
use XML::LibXML               qw( );
use XML::LibXML::XPathContext qw( );

my $doc = XML::LibXML->new->parse_file( 'iXBRL-Tagged_tm213138-13_def14a.htm' );

my $xpc = XML::LibXML::XPathContext->new();
$xpc->registerNs( ix => 'http://...' );

for my $hidden_node ( $xpc->findnodes( '//ix:hidden', $doc ) ) {
   print $_->toString() for $hidden_node->childNodes();
}
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74480228

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档