I have a line like this:
$str =" - group1 - group2 - group3 ";
I also have regex :
/(\-\s\w+)\n(\-\s\w+)\n(\-\s\w+)/
As you know, there are three capture groups: $1 , $2 and $3 . I made this group manually. I mean, if I add this to the line above:
- group4 - group5
Then this regular expression does not match them.
Well, I have a constant pattern: (\-\s\w+) , and I want to create a separate capture group by the number of matching elements in the row. The applicant is a few examples:
Example 1:
$str=" - group 1 ";
I need a regex to pass me the entire line of $1 .
Example 2:
$str=" - group 1 - group 2 ";
I need a regular expression to pass me the first line of the line ( - group 1 ) to $1 and the second line ( - group 2 ) to $2
Well, as you see in the examples above, the line is dynamic, but it matches a constant pattern ... Now I want to know how to create a dynamic capture group according to the line?
source share