Perl正则表达式搜索和替换不匹配

Pez*_*kow 0 regex perl search

我正在尝试使用perl来搜索和替换一些过时的MySQL命令

perl -i -pe 'BEGIN{undef $/;} s/if @RequestID.*@NextValue=@TableNameID output/if @RequestID is not NULL\n                begin\n                        select @TableNameID = @TableNameID + 1/smgi' $file1
Run Code Online (Sandbox Code Playgroud)

但是目前文件在暗示正则表达式不匹配之前和之后仍然完全相同?

smgi打开了标志,所以.*也匹配新行从Multiline搜索替换Perl的建议

这是我想要匹配的文件的剪辑

        if ( @@rowcount = 0 )
                return 1

        update Sequence set CurrentValue = @TableNameID where Code = 'TableName'
end

/* TableNames - Approval Request ID */
if @RequestID is not NULL
begin
        exec spGetNextSequence @Name='TableName', @NextValue=@TableNameID output

        insert into TableName        /* RequestID */
        (
                TableNameID,
                TxnVrsnID,
                FldNmCod,
Run Code Online (Sandbox Code Playgroud)

如果你在http://regexpal.com/(或任何类似的正则表达式测试仪)测试模式- smi在它上面匹配正常吗?

图案: if @ApprovalRequestID.*@NextValue=@TxnDecoratorID output


这是perl稍微分开,所以你可以看到发生了什么

perl -i -pe 'BEGIN{undef $/;} s/
if @RequestID.*@NextValue=@TableNameID output/
if @RequestID is not NULL\n
                begin\n
                        select @TableNameID = @TableNameID + 1
/smgi' $file1
Run Code Online (Sandbox Code Playgroud)

mob*_*mob 5

@name插值为正则表达式模式中的命名Perl数组.逃离@人物:

perl -i -pe 'BEGIN{undef $/;} s/
if \@RequestID.*\@NextValue=\@TableNameID output/
if \@RequestID is not NULL\n
                begin\n
                        select \@TableNameID = \@TableNameID + 1
/smgi' $file1
Run Code Online (Sandbox Code Playgroud)