简体   繁体   English

如何在varnish-vcl中提取字符串的前n个字符?

[英]How to extract first n characters of a string in varnish-vcl?

I'm looking for a way to extract the first 'n' characters from a string in VCL. 我正在寻找一种从VCL中的字符串中提取第一个“ n”个字符的方法。 I couldn't find any function like trim(str,starting_pos) or substring(str,len) in the VCL documentation. 我在VCL文档中找不到任何诸如trim(str,starting_pos)或substring(str,len)的函数。 I've tried searching for this on google and stackoverflow and nothing came up, so I'm asking here. 我尝试在Google和stackoverflow上搜索此内容,但没有任何反应,所以我在这里问。 I appreciate your help. 我感谢您的帮助。

I'm not aware of any such string functions being available in the Fastly Varnish environment. 我不知道在Fastly Varnish环境中可以使用任何此类字符串函数。

However, I think you could accomplish the same using regular expression capture groups. 但是,我认为您可以使用正则表达式捕获组来完成相同的操作。

set req.http.Foo = "foobar";

if (req.http.Foo ~ "^(.{0,3})") {
  set resp.http.match0 = re.group.0; # this should now equal 'foo'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM