The expression to obtain a unique group that is contained by parentheses within parentheses works with the expression below:
string: (test (test (test)))
expression: \(([^()]|(?R))*\)
Link: https://regex101.com/r/JZkXQk/2
If you just swap in the expression where it is '(' for 'begin' and ')' for 'end' does not work
follows example string:
begin
  test1
  test2
begin
  test
  test
end
begin
 test
 test
 test
begin
 test
 test
end
end
end
expression: begin([^(begin)(end)]|(?R))*end
How to use with an regular expression that is contained by words such as BEGIN and END?
 
    