Regex Perl正则表达式搜索和替换不匹配
我试图使用perl来搜索和替换一些过时的MySQL命令Regex Perl正则表达式搜索和替换不匹配,regex,perl,search,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 但是,当前文件在表示正则表达式不匹
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
但是,当前文件在表示正则表达式不匹配之前和之后保持完全相同
我打开了标志smgi
,因此*
也匹配了接受建议的新行
这是我试图匹配的文件的一个片段
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,
如果您在(或任何类似的正则表达式测试仪)上测试模式,并在其上使用smi
匹配良好
模式:if@ApprovalRequestID.@NextValue=@TxnDecoratorID输出
这是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
@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
@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
这就是为什么即使与一行程序一起使用
-w
的原因?编辑:它产生警告,确实如此。在这种情况下,它会立即告诉您问题:可能会在-e第1行的字符串中意外插入@RequestID。
这就是为什么即使使用一行程序也要使用-w
。那么-w做什么呢?编辑:它产生警告,确实如此。在这种情况下,它会立即告诉您问题所在:在-e第1行的字符串中可能意外插入@RequestID。