John
John

Reputation: 487

regular expression help matching a subdirectory for url rewrite

So I need to capture individual sub-directories and assign each of them a reference. The reference order doesn't matter, each reference will be checked individually. Here is an example url:

The URL variables (sub-directories) can also be in any order:

here is my regex so far, but it doesn't work.:

^(?:\w+:\/\/)?(?:[\w.-]+)\/?.*$(\/[0-9a-zA-Z-]+\/){0,12}

Upvotes: 0

Views: 101

Answers (1)

Adam
Adam

Reputation: 5233

Try this one:

^(?:\w+:\/\/)?(?:[\w.-]+)?(\/[0-9a-zA-Z-]+){0,12}\/?

If the above one doesn't work, you should do something like this:

^(?:\w+:\/\/)?(?:[\w.-]+)?(?:(\/[0-9a-zA-Z-]+))?(?:(\/[0-9a-zA-Z-]+))?(?:(\/[0-9a-zA-Z-]+))?(?:(\/[0-9a-zA-Z-]+))?(?:(\/[0-9a-zA-Z-]+))?(?:(\/[0-9a-zA-Z-]+))?(?:(\/[0-9a-zA-Z-]+))?(?:(\/[0-9a-zA-Z-]+))?(?:(\/[0-9a-zA-Z-]+))?(?:(\/[0-9a-zA-Z-]+))?(?:(\/[0-9a-zA-Z-]+))?(?:(\/[0-9a-zA-Z-]+))?\/?

Upvotes: 2

Related Questions