Extracting capturing group contents in Varnish regex

浪尽此生 提交于 2020-01-24 22:55:13

问题


I have the following regular expression in Varnish configuration language

^/abc/([a-zA-Z0-9\-\ ]*)-([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?


回答1:


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.



来源:https://stackoverflow.com/questions/44179243/extracting-capturing-group-contents-in-varnish-regex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!