php - preg_match - What is the pattern of that? -


i have php class url rewriting. want route urls:

 - services-paris/  - services-paris/8/  - services/ 

the formula is: services[ "-" + (city) ]? / [ (0-9) + "/" ]?

first thing [ "-" + (city) ]?, means: optional + must start "-", return city.

second thing [ (0-9) + "/" ]?, means: optional + numbers + end "/" return numbers.

the second thing pagination.

finally need these informations know city , page.

so.. pattern, newbie @ regex.

thanks!

you use regex :

services(?:-([^\/]+))?\/(?:(\d+)\/)?$ 

it's gonna give table of matches contains :

  1. the city name (wihtout '-')
  2. the number after first '/' , before second '/'

note city name mustn't contain '/' character.

example


Comments