kubernetes 在两个参数之间查找多个字符串

y0u0uwnf  于 2022-11-02  发布在  Kubernetes
关注(0)|答案(1)|浏览(133)

我正在尝试创建一个函数,它将在两个参数(rewriteredirect)之间获得一个字符串。我无法理解。
我有一个字符串,看起来像这样:

add_header X-Robots-Tag "noindex, follow" always; rewrite ^/en/about/Administration/index.aspx /en/about/more-about/administration redirect; rewrite ^/en/about/Administration/supervisory-board/index.aspx /nl/over/meer-over/administration redirect; rewrite ^/en/about/Departments-sections-and-fields/index.aspx /en/about/more-about/department-divisions-and-fields redirect; rewrite ^/en/about/For-companies/index.aspx /en/about/more-about/for-companies redirect; rewrite ^/en/about/contact-information/index.aspx /en/about/more-about/contact-information redirect; rewrite ^/en/about/index.aspx /nl/over redirect;

我需要以下输出:

/en/about/Administration/index.aspx /en/about/more-about/administration

/en/about/Administration/supervisory-board/index.aspx /nl/over/meer-over/administration 

/en/about/Departments-sections-and-fields/index.aspx /en/about/more-about/department-divisions-and-fields  

/en/about/For-companies/index.aspx /en/about/more-about/for-companies

/en/about/contact-information/index.aspx /en/about/more-about/contact-information

/en/about/index.aspx /nl/over

什么是正确的正则表达式或方法来获取两个参数之间的所有字符串?

drkbr07n

drkbr07n1#

请尝试:

\brewrite \^(.*?)\s+redirect;

查看在线demo

  • \brewrite \^-在左边的单词边界和右边的空格后跟文字“^”之间按字面意思“重写”;
  • (.*?)-匹配(惰性)0+个字符;
  • \s+redirect;-在左侧的1+个空白字符和右侧的分号之间按字面“redirect”。

查看在线GO demo,其中将打印:

/en/about/Administration/index.aspx /en/about/more-about/administration
/en/about/Administration/supervisory-board/index.aspx /nl/over/meer-over/administration
/en/about/Departments-sections-and-fields/index.aspx /en/about/more-about/department-divisions-and-fields
/en/about/For-companies/index.aspx /en/about/more-about/for-companies
/en/about/contact-information/index.aspx /en/about/more-about/contact-information
/en/about/index.aspx /nl/over

相关问题