core icon indicating copy to clipboard operation
core copied to clipboard

match part of url, to either of the provided phrase or word, without making it optional

Open ThetripGr opened this issue 3 years ago • 0 comments

Hello , i need to do something like the following but i can't seem to get the syntax right or something.

Flight::route("/$langRegex/a-url-part|another-url-part(/@permalink:[0-9a-z\-]+)", function ($permalink) {
   //...rest of code
});

so how I need this to behave ->

  1. First match the languange (a simple e[nl] check )
  2. Then i want to match either a-url-part or another-url-part
  3. Then look for the optional parameter inside the parenthesis, that's after either of the options before

i tried /$langRegex/(a-url-part|another-url-part)(/@permalink:[0-9a-z\-]+) this kinda does work but it makes the (a-url-part|another-url-part) part , optional which is something i do not want because then any url with just /$langRegex/ will match on this route.

Is there a way to make this work with just the syntax or a regex , without duplicating the block of code?

ThetripGr avatar Apr 08 '22 08:04 ThetripGr