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

  • Home
  • SEARCH
  • 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 7665837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:40:44+00:00 2026-05-31T14:40:44+00:00

php > preg_match(@/m(/[^/]+)+/t/?@, /m/part/other-part/t, $m); php > var_dump($m); array(2) { [0]=> string(20) /m/part/other-part/t [1]=>

  • 0
php > preg_match("@/m(/[^/]+)+/t/?@", "/m/part/other-part/t", $m);
php > var_dump($m);
array(2) {
  [0]=>
  string(20) "/m/part/other-part/t"
  [1]=>
  string(11) "/other-part"
}
php > preg_match_all("@/m(/[^/]+)+/t/?@", "/m/part/other-part/t", $m);
php > var_dump($m);
array(2) {
  [0]=>
  array(1) {
    [0]=>
    string(20) "/m/part/other-part/t"
  }
  [1]=>
  array(1) {
    [0]=>
    string(11) "/other-part"
  }
}

With said example I would like the capture to match both /part and /other-part, unfortunately with regex /m(/[^/]+)+/t/? doesn’t capture both, as I expect.

This capture should not be bound to only match this sample, it should capture an undefined number of repetitions of the capture group; e.g. /m/part/other-part/and-another/more/t

UPDATE:
Given that this is expected behavior my question stands as of how I would be able to achieve this matching of mine?

  • 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-31T14:40:45+00:00Added an answer on May 31, 2026 at 2:40 pm

    Try this one out:

    preg_match_all("@(?:/m)?/([^/]+)(?:/t)?@", "/m/part/other-part/another-part/t", $m);
    var_dump($m);
    

    It gives:

    array(2) {
      [0]=>
      array(3) {
        [0]=>
        string(7) "/m/part"
        [1]=>
        string(11) "/other-part"
        [2]=>
        string(15) "/another-part/t"
      }
      [1]=>
      array(3) {
        [0]=>
        string(4) "part"
        [1]=>
        string(10) "other-part"
        [2]=>
        string(12) "another-part"
      }
    }
    

    //EDIT

    IMO the best way to do what you want is to use preg_match() from @stema and explode result by / to get list of parts you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I use the PHP function preg_match() to test a string to see
Hello I would like to use preg_match in PHP to parse the Desired text
<?php $string = Movies and Stars I., 32. part; $pattern = ((IX|IV|V?I{0,3}[\.])); if(preg_match($pattern, $string,
There has always been a confusion with preg_match in php. I have a string
Let's say my URL is this: http://example.com/forum/index.php?topic=53.msg251#msg251 This part here, I can't figure out
I would like to have a php function that will strip any input and
This question is Part 2 of PHP's preg_match_all() to pull out all php tags
I am trying to use PHP preg_math parse a string that looks like: 6.15608128
I want extract the path of images from a html page using PHP-preg_match_all(), the
Is there a shell equivalent of PHP's preg_match? I'm trying to extract the database

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.