How do I handle special characters in a Perl regex?

前端 未结 3 1500
一生所求
一生所求 2020-11-28 14:42

I\'m using a Perl program to extract text from a file. I have an array of strings which I use as delimiters for the text, e.g:

$pat = $arr[1] . \'(.*?)\' . $         


        
3条回答
  •  心在旅途
    2020-11-28 15:05

    Use quotemeta:

    $pat = quotemeta($arr[1]) . '(.*?)' . quotemeta($arr[2]);
    if ($src =~ $pat) 
        print $1;
    

提交回复
热议问题