The regex pattern I tried to use is "\$\{(\b[0-9]+\b)\}(-r\{(.)+\})?(-i\[((\b[0-9]+\b)?:?(\b[0-9]+\b)?)?\])?"
Let me break it down:
I want a decimal number enclosed in ${} which is captured by the first group. This group is mandatory.
-r{} is the second group. Within those braces I want to able to accept a regex pattern string. (hence the "-r{[a-zA-Z]}" in the test string) So I just put (.)+ to accept any character. And this group (-r{}) is optional.
-i group can accept strings like "-i[2]" or "-i[1:2]" or "-i[:2]" or "-i[1:]". And the -i group is optional.
The test works and captures the groups perfectly when there's one string. So I expected to catch multiple matches with similar group of strings separated by space. My test string is "${1}-r{[a-zA-Z]}-i[1:2] ${2}-r{[0-9]}-i[:88]". I wanted "${1}-r{[a-zA-Z]}-i[1:2]" and "${2}-r{[0-9]}-i[:88]" to be separate matches. When I tried it in regex101, it returned as 1 single match and captured "-r{[a-zA-Z]}-i[1:2] ${1}-r{[a-zA-Z]}" as group 2. Link to regex101. When I tried debugging it, I found that when it encountered the (.)+ part, it started parsing from the end of the string. So, I guess that's a mistake if I want to extract multiple matches. What should I do?
Can you even capture a regex pattern enclosed within a string with regex?