I have a string like this:
$str ="
- group1
- group2
- group3
";
Also I have this regex:
/(\-\s\w+)\n(\-\s\w+)\n(\-\s\w+)/
As you know, there is three capturing groups: $1, $2 and $3. I made those group manually. I mean if I append this to the string above:
- group4 
- group5
Then that regex doesn't matches them.
Well, I have a constant pattern: (\-\s\w+), And I want to create a separated capturing group on the number of matches items in the string. Hare is a few examples:
Example1:
$str="
- group 1
";
I need a regex to give me all the string by $1.
Example2:
$str="
- group 1
- group 2
";
I need a regex to give me first line of string (- group 1) by $1 and second line (- group 2) by $2 
Ok well, as you see in the examples above, string is dynamic but it is according to a constant pattern ... Now I want to know how can I create a dynamic capturing group according to the string?
 
     
     
    