0

I am setting up a Zend_Route (but it is still just a regex) and I wish to match a url like

/en/experience/this-is-my-name-and-the-last-is-1-of-id-123456.html

So I want to grab the

this-is-my-name-and-the-last-is-1-of

and the

 123456

I tried

\w{2}/experience/(.+)?-(\d+)\.html  

but that doesn't seem to work.

It would be easy if the other way around e.g. if it was id the name

/en/experience/123456-this-is-my-name-and-the-last-is-1-of-id.html

I could use

\w{2}/experience/(\d+)-(.+)\.html

But that is a cop out - so any advice on how to match original format?

2
  • 1
    Your regex works fine for me: rubular.com/r/Ou5N48bV2Q Commented Jun 9, 2011 at 12:35
  • So do you not want to match the -id- bit? Your example doesn't show it Commented Jun 9, 2011 at 12:38

2 Answers 2

1

Try this one:

/\w{2}/experience/(.+?)-(\d+)\.html
Sign up to request clarification or add additional context in comments.

Comments

0

try this:
/\w{2}/experience/(.+)?-(\d+)\.html

zend route internally does this:
preg_match('#^/\w{2}/experience/(.+)?-(\d+)\.html$#i', '/en/experience/this-is-my-name-and-the-last-is-1-of-id-123456.html', $matches);

so, your pattern only matches with a slash on the beginning.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.