Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 要匹配的Perl正则表达式<;foo>;eof_Regex_Perl_Ultraedit - Fatal编程技术网

Regex 要匹配的Perl正则表达式<;foo>;eof

Regex 要匹配的Perl正则表达式<;foo>;eof,regex,perl,ultraedit,Regex,Perl,Ultraedit,如何使用Perl正则表达式搜索来查找以以下内容结尾的文件: -------\r\n<eof> 我在UltraEdit,它说它使用BoostPerlRegex语法 我已经想出了足够的方法来使用: ----\x0d\x0a 它确实找到了我想要的行,但只在数百行不在文件末尾的行中找到: whatever ------------ <- matches this also, which I don't want! whatever ------------ <

如何使用Perl正则表达式搜索来查找以以下内容结尾的文件:

-------\r\n<eof>
我在UltraEdit,它说它使用BoostPerlRegex语法

我已经想出了足够的方法来使用:

----\x0d\x0a
它确实找到了我想要的行,但只在数百行不在文件末尾的行中找到:

whatever
------------     <- matches this also, which I don't want!
whatever
------------     <- matches this also, which I don't want!
whatever
不管怎样
------------UltraEdit的正则表达式引擎以基于行的方式工作。这意味着除其他外,它不会区分行的末尾和文件的末尾

它也不知道
\z
\z
字符串结束标记。另外,像
----\r\n(?)
这样的负面前瞻断言在UE中不起作用

所以UE的正则表达式引擎让你在这里。您可以使用宏:

InsertMode
ColumnModeOff
HexOff
Key Ctrl+END
Key UP ARROW
PerlReOn
Find RegExp "-----\r\n"
IfFound
# Now do whatever you wanted to do...
EndIf

并让UE将其应用于所有文件。

是否需要迭代文件中的每一行并使用正则表达式?如果没有,只需
查找所需文件中的位置,并检查字符串是否相等:

open my $fh, '<', $the_file;
seek $fh, 2, -6;            # seek to the end of file minus 6 bytes
read $fh, my $x, 6;         # read 6 bytes into $x
if ($x eq "----\r\n") {
    print "The end of file matches ----\\x0d\\x0a\n";
} else {
    print "The end of file doesn't match ----\\x0d\\x0a\n";
}

打开我的$fh,”这里有一种使用UltraEdit JavaScript的方法

使用UltraEdit.activeDocument.bottom()转到文件的底部; 使用UltraEdit.activeDocument.currentPos();以存储当前位置

向后搜索“\r\n” 再次使用UltraEdit.activeDocument.currentPos();并将结果与前面的位置进行比较,以确定这是否实际上是文件末尾的cr/lf

根据这些字符的位置,做任何你想做的替换/插入操作,或者弹出一个消息框宣布结果

open my $fh, '<', $the_file;
seek $fh, 2, -6;            # seek to the end of file minus 6 bytes
read $fh, my $x, 6;         # read 6 bytes into $x
if ($x eq "----\r\n") {
    print "The end of file matches ----\\x0d\\x0a\n";
} else {
    print "The end of file doesn't match ----\\x0d\\x0a\n";
}