Complex Regex In Urlmanager Rule For Yii 1.1.13

Hello,

new to Yii.

I want to write a urlManager regex rule that matches to following for the ‘id’ parameter in a url:


d12361287

p324782

d3777

But doesn’t match those


uasi8

sdhajk9

asdjhjask

So the rules are

  • first character hast to be ‘d’ or ‘p’

  • then following are only numeric values of variable length

I tried this regex, which works on all the test websites: ^[dp][0-9]*$

integrated it this way but doesn’t work as expected


'rules' => array(

	'<controller:(car|used-cars|new-cars)>/<id:(^[dp][0-9]*$)>/<title>' => 'car/view',

	...

Can anyone help me and point out what i’m doing wrong?

Can you be more specific? Also: I think your regex is slightly flawed as it will also match just [font="Courier New"]d[/font] and [font="Courier New"]p[/font]. Try this:




'<controller:(car|used-cars|new-cars)>/<id:([dp]\d+)>/<title>' => 'car/view',



Thank you, that code does what i was looking for.