英文:
Find multiple strings between two arguments
问题
我正在尝试创建一个函数,该函数将获取两个参数(rewrite和redirect)之间的字符串。我无法理解它。
我有一个看起来像这样的字符串:
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
获取两个参数之间所有字符串的正确正则表达式或方法是什么?
英文:
I'm trying to make a function that will get a string between two arguments (rewrite and redirect). I can't wrap my head around it.
I have a string that looks like this:
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;
And I want the following output:
/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
What is the proper regex or method to get all strings between the two arguments?
答案1
得分: 0
尝试:
\brewrite \^(.*?)\s+redirect;
在线演示:点击这里
\brewrite \^
- 字面上是在左边的单词边界和右边的空格后面跟着字面上的^
;(.*?)
- 匹配(懒惰模式)0个或多个字符;\s+redirect;
- 字面上是在左边的1个或多个空白字符和右边的分号后面跟着字面上的redirect
。
查看在线的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
英文:
Try:
\brewrite \^(.*?)\s+redirect;
See an online demo
\brewrite \^
- literally 'rewrite' between a word-boundary on the left and a space followed by literal '^' on the right;(.*?)
- Match (lazy) 0+ characters;\s+redirect;
- Literally 'redirect' between 1+ whitespace characters on the left and a semi-colon on the right.
See an online GO demo which will print:
/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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论