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 6755955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:27:54+00:00 2026-05-26T13:27:54+00:00

I have URI route like: /dir/:dir1/:val1-:val2 I need a regular expression to: Know if

  • 0

I have URI route like:

/dir/:dir1/:val1-:val2

I need a regular expression to:

  1. Know if the route match the real URI (es. /category/cars/ferrari-10)
  2. Get parameters and values like the follow:

    dir1 => cars

    val1 => ferrari

    val2 => 10

How to do this job?

THank you!

  • 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-26T13:27:55+00:00Added an answer on May 26, 2026 at 1:27 pm

    Using regex named groups and preg-match:

    $test = "/category/cars/ferrari-10";
    $result = preg_match("/^\/[^\/]+\/(?P<dir1>[^\/]+)\/(?P<val1>[^-]+)-(?P<val2>[^\/]+)$/", $test, $matches);
    print_r($matches);
    

    The above will result in the following array:

    Array
    (
        [0] => /category/cars/ferrari-10
        [dir1] => cars
        [1] => cars
        [val1] => ferrari
        [2] => ferrari
        [val2] => 10
        [3] => 10
    )
    

    Also, if you want to remove the unnamed groups, you can use the following:

    for ($i = 0; $i < count($matches); $i++) {
      unset($matches[$i]);
    }
    

    References:

    • preg-match
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a route in my route.php : $route['admin/(:any)'] = 'ix/$1'; It routes URI
I have a uri scheme which is like <country>/<id>_<action>/<name> which descends from an old
I have a URI here in which a simple document.cookie query through the console
I have a Uri object being passed to a constructor of my class. I
I have: String uri = @drawable/myresource.png; How can I load that in ImageView? this.setImageDrawable?
I have a System.Uri, e.g., var uri = new Uri(http://www.domain.com/foo/bar); How do I get
I have an android.net.URI object (of the kind returned by onActivityResult after MediaStore.ACTION_VIDEO_CAPTURE): it
I have a convenience class for encoding URI's. In it I've created three methods
I have a RESTful API containing a URI of /UserService/Register. /UserService/Register takes an XML
I have got this code: XDocument xdoc = XDocument.Load(URI); XElement root = xdoc.Element(forecast); //get

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.