Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6131035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:55:38+00:00 2026-05-23T16:55:38+00:00

Currently, I have a simple router class that takes URIs and attempts to match

  • 0

Currently, I have a simple router class that takes URIs and attempts to match them to the incoming request URI. A simple example of a route it might try to match to the request URI would be:

/user/([0-9]+)

So, this would match a request URI of “user/1”.

Now I’m trying to match optional parameters. This works:

/user([/0-9]?)

However, it seems like this would allow any number of slashes in the segment. How can I force the optional segment to be preceded by one slash and then numbers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:55:39+00:00Added an answer on May 23, 2026 at 4:55 pm

    Try the following regular expression:

    /user(/[0-9]+)?
    

    It will match “/user” followed by “/” plus one or more digits or “/user” alone. If you want to group the digits only you can enclose it in a non-capturing group:

    /user(?:/([0-9]+))?
    

    You can enclose it in ^ and $ in the call to preg_match:

    preg_match( "/^\/user(?:\/([0-9]+))?$/", "/user/1234", $m);
    print_r($m);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a Perl CGI script that parses incoming XML requests using XML::Simple
So I have a PHP class called router that takes the URL and explodes
I currently have a simple form that when you click the save button will
Currently I have a simple maven project that is building a jar file and
I have a (currently very simple) website that is utilising Facebook's Website with Facebook
Currently I have a simple knockoutJS object, with a few observables. But this object
I currently have a very simple MySQL database (articlesDB) with 1 table (articles) and
I own a video streaming website and currently I just have a simple hit
Very simple + silly question: Does clojure provide multi maps? I currently have something
I have a simple ticket logging application build on LAMP. I am currently playing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.