正则表达式 – Perl提取文本
发布时间:2020-12-14 05:50:10 所属栏目:百科 来源:网络整理
导读:我一直在研究这个问题! 我很感激你的帮助…… 我的文档会是什么样子: texttext command += "stuff_i_need" texttexttext command += stuff texttexttext command += -stuff texttext 任何带有缠绕括号的东西都是可选的 东西可以是任何东西(苹果,橙子,香蕉)
我一直在研究这个问题!
我很感激你的帮助…… 我的文档会是什么样子: <text> <text> command <+>= "stuff_i_need" <text> <text> <text> command <+>= stuff <text> <text> <text> command <+>= -stuff <text> <text> >任何带有缠绕括号的东西都是可选的 我的代码到目前为止: #!/usr/bin/env perl use warnings; use strict; use Text::Diff; # File Handlers open(my $ofh,'>in.txt'); open(my $ifh,'<out.txt'); while (<$ifh>) { # Read in a line my $line = $_; chomp $line; # Extract stuff my $extraction = $line; if ($line =~ /command += /i) { $extraction =~ s/.*"(.*)".*/$1/; # Write to file print $ofh "$extractionn"; } } 解决方法
根据示例输入:
if ($line =~ /commandd*s*+?=s*["-]?(w+)"?/i) { $extraction = $1; print "$extractionn"; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |