Nginx rewrite regular expression that matches non-Words

Source: Internet
Author: User

Because you want to rewrite an address from
/MAG/XX/XXX/->/M/xxx
But the original/MAG/XX/more/should be retained
In this case, you have to write a strange regular expression. I have tried a lot of writing methods and I have not succeeded.

The first thing to think about is:

Location ~ * ^/MAG/[^/] +/[^ (more)] + /{
Rewrite ^/MAG/[^/] +/(. *)/M/$1 permanent;
}

[] Is not effective in writing. It matches a single character, which is invalid and cannot be matched.

I am still a good friend of fan. I have studied deeply and provided some non-certain words (?! More)

Location ~ * ^/MAG/[^/] + /(?! More) ([^/] + )/{
Rewrite ^/MAG/[^/] +/(. *)/M/$1 permanent;
}

This statement is barely enough. Although the matching unit is not perfect, it can also deal with all my requirements.
If necessary, refer to this method.

Common grouping syntax

Capture
(Exp) Match exp and capture the text to the automatically named group
(? Exp) Match exp, and capture the text to the group named name. You can also write (? 'Name' exp)
(? : Exp) matches exp, does not capture the matched text, and does not assign group numbers to this group.

Assertion with Zero Width
(? = Exp) match the position before exp
(? <= Exp) match the position behind exp
(?! Exp) the position behind the matching is not the exp position.
(? ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.