Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.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 启用quotemeta的字符串无法匹配特定的正则表达式_Regex_Perl_Quotemeta - Fatal编程技术网

Regex 启用quotemeta的字符串无法匹配特定的正则表达式

Regex 启用quotemeta的字符串无法匹配特定的正则表达式,regex,perl,quotemeta,Regex,Perl,Quotemeta,对于以下启用quotemeta的字符串,if语句无法匹配.cpp和.o文件名。我做错什么了吗 E\:\\P4\\NTG5\\PATHOLOGY_products\\arm\-qnx\-m650\-4\.4\.2\-osz\-trc\-dbg\\gen\\deliveries\\ntg5\\arm\\api\\sys\\most\\pf\\mss\\src\\private\\DSIDSYSMOSTServerMoCCAStream\.cpp\ 为什么文件名要在quotemeta中运行?正如

对于以下启用quotemeta的字符串,if语句无法匹配.cpp和.o文件名。我做错什么了吗

E\:\\P4\\NTG5\\PATHOLOGY_products\\arm\-qnx\-m650\-4\.4\.2\-osz\-trc\-dbg\\gen\\deliveries\\ntg5\\arm\\api\\sys\\most\\pf\\mss\\src\\private\\DSIDSYSMOSTServerMoCCAStream\.cpp\



为什么文件名要在quotemeta中运行?正如您所演示的,这将使您所有的's'都摆脱反斜杠。因此,如果这是您想要匹配的,那么您必须在正则表达式中添加一些反斜杠

if ($a_path =~ m/[\\>](\w+\\\.(?:cpp|c))/) {


正则表达式匹配一个单词字符,后跟一个
;如果字符串在每个
前面都有反斜杠,则它们将不匹配


不知何故,您没有正确地考虑这一点:“quotemeta”不是启用或禁用的内容,它是一个在字符串中的某些字符之前粘贴反斜杠的操作符。为什么要首先使用它?

此处\w+无法匹配,但m/\.(?:cpp|c)$/匹配。但是为什么\w+在这里无法匹配。我需要将基于windows的路径与反斜杠匹配,没有quotemeta,我遇到以下错误--无法通过unicode/is/e.pl第0行的main-e或e.pl找到unicode字符属性定义--因此我使用了quotemeta。我将使用$a_path=~s!\!/!G以消除所有混淆。您遇到了以下错误?所以你使用quotemeta是因为你试图避免程序中的其他缺陷?我想我们现在面临的是一场危机。为什么不在你开始幻想之前准确地解释一下你想做什么,以及你遇到了什么问题呢。您可以编辑原始问题线程。原始问题是我遇到错误:无法通过unicode/Is/e.pl第0行的main-e或e.pl找到unicode字符属性定义——因为我使用了拆分($a_行,/\s+/);这是错误的调用方式,因为$a_行包含windows路径和文件名。我改为split(/\s+\,$a\u行),然后使用out quotemeta进行操作。看起来OP假设应该对字符串而不是正则表达式应用
quotemeta
        if ($a_path =~ m/[\\>](\w+\.(?:cpp|c))/) {
            $compile_line_array->source_filename($a_path);
            $compile_line_array->include_list_index($include_path_cnt);
            $j=0;
            last;
        } 

        if($a_path =~ m/[\\>](\w+\.(?:o))/) {
            $compile_line_array->object_file($a_path);
        }
if ($a_path =~ m/[\\>](\w+\\\.(?:cpp|c))/) {
if($a_path =~ m/[\\>](\\\w+\.(?:o))/) {