Search

I'm using the URL Router and URL Segments extensions among other things for a custom approach to a multi-region and multilingual project.

Rubular permalink.

My URLs will be in the following format:

/:region/:language/page-name(s)/param(s)

E.g.:

/gb/en/tours/lesson-observation

In the URL Router route from field I currently have:

/^/(.[^/])/(.[^/])/(.*)/

to:

/$3/

This seems to be working fine, and I still have access to gb and en (or whatever they are) via URL Segment's url-segment-1 and url-segment-2 parameters for data source filtering.

My question is: how can I tighten up the matching of the regular expression so that the first two URL segments must be of certain length ranges (2-3 and 2-5 respectively)?

And should I be more specific than .[^/] (any characters except for /)?

Thanks.

This should work for you

/^/(.{1,2}[^/])/(.{1,4}[^/])/(.*)/

http://www.rubular.com/r/gbWWBt3GSO

Brilliant - thank you.

As well as not putting the number ranges in the right place, I didn't realise that 2-3 characters is described as {1,2}; I would have thought it would have been {2,3}, which is what I interpreted this as saying. Not sure if it's a different in regex implementation or to do with the / negation or something else. Oh well. :-)

Actually it should be {2,3} but for some reason the [^/] messes it up, I'm not really sure why.

Yes, [^/] consumes one of the characters apparently.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details