English 中文(简体)
简单 必需的贴身帮助
原标题:Simple Perl script help required

我期望制作一张纸面,我将在Java文本档案上操作,以便自动改变(......),打破文字。

例:

档案。

document.writeln( &#187; <a href="/LINK1" TARGET="_blank">Lorem ipsum lorem 1</a><br> );

document.writeln( &#187; <a href="/LINK2" TARGET="_blank">Lorem ipsum lor em x em 2</a><br> );

document.writeln( &#187; <a href="/LINK3" TARGET="_blank">Lorem ipsum lorem 3</a><br> );

在第2行“Lorem ipsum lor em x 2”中,有单一引文,将用文字删除。 只字句的休息将如“文件”。

最佳回答

定期表达:

$data =~ s/
    (?<!   # negative look-behind
        ( #   ensure no open parenthesis behind
    )
           # a quote mark
    (?!    # negative look-ahead
        ) #   ensure no close parenthesis ahead
    )
/\ /xsg;

第二行:

document.writeln( &#187; <a href="/LINK2" TARGET="_blank">Lorem ipsum lor em x em 2</a><br> );

产出:

document.writeln( &#187; <a href="/LINK2" TARGET="_blank">Lorem ipsum lor em x em 2</a><br> );

简单的文字可以是:

while ( <> ) {
    $_ =~ ... # regular expression given above
    print $_;
}

您将为此打字:

perl myscript.pl file.js
问题回答

最为简单的办法是替换所有<代码>,然后替换安全代码,其行文如下:

s/ /\ /g; # replace all single quotes
s/document.writeln(\ /document.writeln( /g; # revert safe occurrences 

显然,这种解决办法是一种速效和 d脏的固定办法,只有你控制你的投入,而且如果输入格式众所周知,就会失败。





相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签