Forum

Thread tagged as: Discussion, Offtopic, Runway

Blogslug custom token

I am studying the blogslug Custom Token to better understand the regular expressions used in the example version.

And just have a couple of questions to help me understand how it works. They're regular expression questions rather than Perch questions really.

In the example:

'blogslug' => '[1-2][0-9]{3}\-[0-9]{2}\-[0-3][0-9]-[a-z0-9\-]+',

is used for the standard slug for Blog, like this

2014-12-01-christmas-is-near

As I read through the regular expression it seems to make sense when comparing it to the slug, but after the part that defines the date there is a - (dash) shouldn't that be escaped with a \ (backslash)? i.e.

'blogslug' => '[1-2][0-9]{3}\-[0-9]{2}\-[0-3][0-9] (backslash here to escape this dash) -[a-z0-9\-]+',

And what does the + signify at the end?

Thanks for any help in understanding.

Simon Clay

Simon Clay 127 points

  • 6 years ago

It means 1 or more.

Drew wrote a great article for 24ways a couple of years ago, that should help:

There's a section called Matching Patterns

https://24ways.org/2013/url-rewriting-for-the-fearful/

Simon Clay

Simon Clay 127 points

Ah, that makes sense, thanks. And what do you think about escaping the dash?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It's slightly over-zealous escaping. Not necessary, but does no harm.

Simon Clay

Simon Clay 127 points

Understood, thank you both very much.