user3392184
user3392184

Reputation: 13

Strings with quotemeta enabled not able to match specific regex

For following strings with quotemeta enabled, the if statements are not able to match .cpp and .o file names. Am I doing anything wrong here.

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\

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

        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);
        }

Upvotes: 0

Views: 219

Answers (2)

ysth
ysth

Reputation: 98398

The regexes match a word character followed by a .; if your strings have a backslash before every ., they will not match.

Somehow, you are not thinking about this correctly: "quotemeta" isn't something that is enabled or disabled, it is an operator that sticks backslashes before some characters in your string. Why are you using it in the first place?

Upvotes: 2

Miller
Miller

Reputation: 35208

Why do you have your filenames run through quotemeta? As you've demonstrated, that's going to backslash escape all your .'s. Therefore if that's what you want to match against, you'll have to add some backslashes to your regex.

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

or

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

Upvotes: 0

Related Questions