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?
CodePudding user response:
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