0

I've been trying to use regex to determine if the current URL matches to either http://test.com or http://test.com/page/[0-9]+

I've been looking at countless of tutorials but couldn't find any that tackled anything even remotely such as this. I've tried just about everything but I'm just too inexperienced with regex to get it going.

Thank you for your help and I hope you could point me in the right direction.

adamj
  • 4,672
  • 5
  • 49
  • 60
  • 1
    Show your code. Explain what "current URL" refers to. Variable matching? CGI environment? Or a .htaccess rule?? * See also [Open source RegexBuddy alternatives](http://stackoverflow.com/questions/89718/is-there) and [Online regex testing](http://stackoverflow.com/questions/32282/regex-testing) for some helpful tools, or [RegExp.info](http://regular-expressions.info/) for a nicer tutorial. – mario Feb 05 '13 at 00:53
  • I do see the confusion. 'current URL' refers to the full URL that you are on i.e. http://test.com/hello/world. I have it tagged as PHP and preg_match which I thought would be self explanatory but all I'm trying to do is run a pattern that matches it to the URL you are currently on. Those links are awesome! These will save me quite a lot of headaches =) – adamj Feb 05 '13 at 04:17

1 Answers1

2

You can try

"http://test\.com(?:/page/[0-9]+)?"
Philipp
  • 15,377
  • 4
  • 35
  • 52
  • Could you please explain more about `?:`. What does it do? Is it just for performance reasons? – Sina Iravanian Feb 05 '13 at 01:40
  • ?: starts a subpattern - means this doesn't appear in the matches-param from preg_match – Philipp Feb 05 '13 at 01:46
  • Thank you. This almost worked for me, I just had to tweak it a little `http://test\.com(?:/page/[0-9]+)?$` just to force it work with only the specific URLs. Thanks man! I owe you a virtual beer =) – adamj Feb 05 '13 at 04:27