在 Varnish 正则表达式中提取捕获组内容 [英] Extracting capturing group contents in Varnish regex
本文介绍了在 Varnish 正则表达式中提取捕获组内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Varnish 配置语言中有以下正则表达式
I have the following regular expression in Varnish configuration language
^/abc/([a-zA-Z0-9\-\ ]*)-([0-9]+)
现在,我想在 Varnish 中获取正则表达式的值 $2
部分(即 [0-9]+
).
Now , I want fetch the value $2
part(i.e [0-9]+
) of regular expression in Varnish.
我怎样才能得到这个值?
How can I get this value?
推荐答案
你可以在这种情况下使用 regsub
:
You may use regsub
in this case:
set req.url = regsub(req.url, "^/abc/([a-zA-Z0-9 -]*)-([0-9]+).*", "\2");
您匹配整个字符串,捕获您需要的部分,并替换为适当的反向引用.
You match the whole string, capture the part you need, and replace with the appropriate backreference.
这篇关于在 Varnish 正则表达式中提取捕获组内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文