Sublime Text 正则表达式仅在未转义时有效

Sublime Text regex working only if not escaped

在sublime text 3中,为什么匹配3个条目

$http\.post\('\/((?!view|list).)[^\']*'

但这什么都不匹配

$http\.post\('\/((?!view|list).)[^\']*\'

在以下数据集上。

$http.post('/listSets' ,$scope.updateAccessKey({type: 2}), {
$http.post('/viewedMessage' , viewedMessagePayload, {
$http.post('/listRelatedContent' , 
$http.post('/viewedSet' , payLoad , {
$http.post('/viewDiscussion' , payLoad , {
$http.post('/editMessage' , $scope.updateAccessKey(payLoad), {
$http.post('/addComment' , $scope.updateAccessKey(payLoad), {
$http.post('/createStudySet' , createSetP

我知道转义撇号是可选的,但为什么它会破坏 Sublime Text 正则表达式搜索?

根据 documentation on Search and Replace, internally Sublime uses the Boost PCRE engine to power regular expressions in search panels, and according to the Boost Regex documentation,构造 \'\z 同义,仅在缓冲区末尾匹配。

所以以 \' 结尾的正则表达式版本不匹配任何内容,因为根据定义它只匹配看起来像 $http.post 行的内容,该行出现在文件的最后一行并以 URL 字符串结尾的文件仍未终止。

由于正则表达式中 \' 之前的 *,它将匹配该行后面的任意数量的文本,只要它不包含单引号(由于排除字符 class).

例如,给定以下输入,您的正则表达式将匹配最后一个 $http.post,包括它后面的所有内容,直到缓冲区的末尾。

$http.post('/listSets' ,$scope.updateAccessKey({type: 2}), {
$http.post('/viewedMessage' , viewedMessagePayload, {
$http.post('/listRelatedContent' , 
$http.post('/viewedSet' , payLoad , {
$http.post('/viewDiscussion' , payLoad , {
$http.post('/editMessage' , $scope.updateAccessKey(payLoad), {
$http.post('/addComment' , $scope.updateAccessKey(payLoad), {
$http.post('/createStudySet , $scope.updateAccessKey(payLoad), {

And then some other non code stuff here.
Basically anything but a single quote.