Regex doesn’t match subgroups as expected

  Kiến thức lập trình

I am writing a C program that makes use of regex to detect a string like:

hl # # #

Where # indicates an integer. Up to 11 integer values should be captured here

I have written the following regular expression to satisfy this, (and below that, I provided a sample value) :

#define HARDLINK_MATCH_EXPRESSION "^hl( ([1-9][0-9]*))*( ([1-9][0-9]*))*( ([1-9][0-9]*))*( ([1-9][0-9]*))*( ([1-9][0-9]*))*( ([1-9][0-9]*))*( ([1-9][0-9]*))*( ([1-9][0-9]*))*( ([1-9][0-9]*))*( ([1-9][0-9]*))*( ([1-9][0-9]*))*"
char *sampleValue = "hl 1 2 3 4 5 6 7 8 9 10 11" ;

However, in both the C program and at https://regex101.com/ I find that the string matches, but only one integer (the last one) is “captured.” My thinking is that this defines a series of eleven greedy “outer” groups, and I expected that each group would be satisfied by this example.

I have pored through uncounted solutions to this sort of problem, and though I’m certain my question is probably not unique, I couldn’t find a match in the multitude of answers.

Can someone explain why the expression does not capture the inner groups as well as the final (until the expression runs out at 11 captures) ??

Thanks.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT