为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

Go
莫回无 2023-02-28 20:24:05
我正在尝试创建一个函数,它将在两个参数(重写和重定向)之间获取一个字符串。我无法理解它。我有一个看起来像这样的字符串: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获取两个参数之间的所有字符串的正确正则表达式或方法是什么?
查看完整描述

1 回答

?
胡子哥哥

TA贡献1825条经验 获得超6个赞

尝试:

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

查看在线演示


  • \brewrite \^- 在左侧的单词边界和右侧的空格后跟文字“^”之间字面地“重写”;

  • (.*?)- 匹配(惰性)0+ 个字符;

  • \s+redirect;- 在左侧的 1+ 个空白字符和右侧的分号之间“重定向”。


查看将打印的在线 GO演示:

/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


查看完整回答
反对 回复 2023-02-28
  • 1 回答
  • 0 关注
  • 58 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信