digout
digout

Reputation: 4252

Correct regex / mod-rewrite syntax for this url

Hi I am having a little difficulty working out this mod rewrite rule / regex correctly.

I have a url format like this:

www.site.com/some-page-title-here-cb384

www.site.com/another-page-title-here-cb385

And I'd like to find only the numbers after each 'cb' only if the url contains a 'cb' after the last hyphen in each string.

I have:

.*?([0-9]+)$

Which matches the last set of numbers but I need to be more specific in saying only if the last section of the url contains the pattern '-cb'.

Upvotes: 0

Views: 71

Answers (1)

Zagorax
Zagorax

Reputation: 11890

Try this:

.*-cb(\d+)$

This one should work and you should find the numbers in $1.

Let me be more specific. Your regexp (and mine above) doesn't match only the last part of the string, but matches the whole string. If you want to match only the last part, you should write it without .*:

-cb(\d+)$

Upvotes: 1

Related Questions