Asked  7 Months ago    Answers:  5   Viewed   27 times

I'm trying to get all substrings matched with a multiplier:

$list = '1,2,3,4';
preg_match_all('|d+(,d+)*|', $list, $matches);

This example returns, as expected, the last match in [1]:

    [0] => Array
            [0] => 1,2,3,4

    [1] => Array
            [0] => ,4


However, I would like to get all strings matched by (,d+), to get something like:

    [0] => ,2
    [1] => ,3
    [2] => ,4

Is there a way to do this with a single function such as preg_match_all()?



According to Kobi (see comments above):

PHP has no support for captures of the same group

Therefore this question has no solution.

Wednesday, March 31, 2021
answered 7 Months ago

You can use:

preg_match_all("!<span[^>]+>(.*?)</span>!", $str, $matches);

Then your text will be inside the first capture group (as seen on rubular)

With that out of the way, note that regex shouldn't be used to parse HTML. You will be better off using an XML parser, unless it's something really, really simple.

Saturday, May 29, 2021
answered 5 Months ago

This regex will do the trick:

(d+)d (d+)h (d+)m (d+)s

Each value (day, hour, minute, second) will be captured in a group.

About your regex: I don't know what do you mean by "isn't correct", but I guess it's probably failing because your regex is greedy instead of lazy (more info). Try using lazy operators, or using more specific matches (d instead of ., for example).


I need them to be separate variables

After matching, they will be put in different locations in the resulting array. Just assign them to variables. Check out an example here.

If you have trouble understanding the resulting array structure, you may want to use the PREG_SET_ORDER flag when calling preg_match_all (more information here).

Saturday, May 29, 2021
answered 5 Months ago

You could try the below regex which uses positive lookahead assertion.

(?=(bw+ Road d+b)|(bd+ suiteb))


String s = "XYZ Road 123 Suite";
Matcher m = Pattern.compile("(?i)(?=(\b\w+ Road \d+\b)|(\b\d+ suite))").matcher(s);
    if( != null) System.out.println(;
    if( != null) System.out.println(;


XYZ Road 123
123 Suite
Friday, August 20, 2021
Andy Fedoroff
answered 2 Months ago

NOTE AngularJs 1.3 now supports Getter/Setter for ng-model. Refer to for more information.

I could break the infinite loop with extra calls to




in the event handlers. Not sure if it's the best way to do it though.

See fiddle:


I improved the code even more in

by separating the directive in separate ones for the getter and the setter.

Saturday, October 9, 2021
answered 1 Week ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :