Closed Fredida closed 3 weeks ago
有两种写法:
# 正则
/https://domain/path-aaa/ran(\d\d)/path-bbb/file-/ file://X:\mock-domain\path-aaa\rand$1
# 通配符
^https://domain/path-aaa/ran*/path-bbb/file-* file://X:\mock-domain\path-aaa\rand$1
感谢作者的帮助,抱歉之前表述的有歧义,其实是想把
/https://domain/path-aaa/ran\d\d/path-bbb/file-1
/https://domain/path-aaa/ran\d\d/path-ccc/file-2
都匹配到
file://X:\固定dir\
下
(X:\固定dir下有path-bbb\file-1和path-ccc\file-2等)
请问该如何撰写规则呢?
提问之前有阅读过帮助文档pattern.html,请问这段描述
最多支持10个子匹配 $0...9,其中$0表示整个请求url,其它跟正则的子匹配一样 /[^?#]\/([^\/]+).html/ protocol://...$1...
应该理解为$1为正则第一次匹配之后剩余的后续url部分?那么$2(对应的子匹配)是什么呢?
跟正则的子匹配一样,试试:
^https://domain/path-aaa/ran*/** file://X:\固定dir\$2
有n个待匹配的url例如:
https://domain/path-aaa/ran02/path-bbb/file-d
https://domain/path-aaa/ran67/path-ccc/file-e
其中ran后面为定长2位的随机数本地目录X:\mock-domain\path-aaa\randxx分别有子目录path-bbb和path-ccc存放了file-d和file-e 写了一条正则rule匹配这类url让他们分别访问对应子目录里的文件:
/https://domain/path-aaa/ran\d\d/path-bbb/file-d/ file://X:\mock-domain\path-aaa\randxx
但实际测试对于任何匹配上的url都会只自动访问到
X:\mock-domain\path-aaa\randxx
,请问有简洁的正则办法让程序在randxx之后根据url自动拼接访问吗?另外不知道whistlek可不可以debug rule(规则)的解析与执行的过程,这样可以自行调试发现自己写的rule在哪里系统解析结果和预想的不一样,就能少提issue来麻烦作者了。