Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.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
Ruby 使用非转义\字符插入变量的正则表达式_Ruby_Regex - Fatal编程技术网

Ruby 使用非转义\字符插入变量的正则表达式

Ruby 使用非转义\字符插入变量的正则表达式,ruby,regex,Ruby,Regex,下面我将尝试解析UNRR提取.rar的输出。我有下面一行抛出错误:转义序列太短。这是由于变量extractLocation等于具有未转义字符的文件路径(例如I:\Rar\Backups\)。有没有办法在我的正则表达式中引用这个变量的文本字符串解释?如果没有,我可以采取什么其他方法来解决这个问题 stdoutArr = stdout.split("\n") stdoutArr.each do |line| #line below is throwing the error if line.

下面我将尝试解析UNRR提取.rar的输出。我有下面一行抛出错误:转义序列太短。这是由于变量extractLocation等于具有未转义字符的文件路径(例如I:\Rar\Backups\)。有没有办法在我的正则表达式中引用这个变量的文本字符串解释?如果没有,我可以采取什么其他方法来解决这个问题

stdoutArr = stdout.split("\n")

stdoutArr.each do |line|
#line below is throwing the error   
if line.match(/((?<=(Extracting  #{extractLocation})).*.bak)/)
        extractedFile = line[(/((?<=(Extracting  #{extractLocation})).*.bak)/)]
    end
end
stdoutar=stdout.split(“\n”)
Stdoutar.每条do |线|
#下面的行抛出了错误
如果line.match(/(?尝试此选项

regexp = /((?<=(Extracting  #{Regexp.escape(extractLocation)})).*.bak)/
regexp=/(?试试这个

regexp = /((?<=(Extracting  #{Regexp.escape(extractLocation)})).*.bak)/
regexp=/(?