regular express : how to exclude multiple character groups?

前端 未结 3 2084
既然无缘
既然无缘 2021-02-07 18:47

I have a set of urls :

/products

/categories

/customers

Now say a customers is named john, and I want to help john to reac

3条回答
  •  再見小時候
    2021-02-07 19:12

    You're trying to use a negated character class the wrong way. A negated character class says 'do not match the contained characters'. What you are wanting to say is 'do not match if this stuff I specified here exists'. To do that you have to a bit more creative. Probably need some negative lookbehind. I'm not 100% sure about php's regex engine but something similar to this should work.

    /^\/(?

    so, negative lookbehind (? saying don't match the .+ if products or categories or admin precede it. Then that is in a non-capturing group (?: ... ).

    Check out Regular Expression Advanced Syntax Reference for extra help.

提交回复
热议问题