0

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?

NightOwl888
  • 51,095
  • 20
  • 122
  • 194
  • Which language are you using? It's important to add that information to questions tagged regex because each engine acts differently (especially when recursion is being considered) – ctwheels Mar 12 '18 at 13:52
  • It's because you're putting the characters in a set, so you're just matching any character except `(begin)d` (after removing duplicates). – ctwheels Mar 12 '18 at 13:55
  • You are confusing character classes with grouping constructs. [Read more about them.](https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – revo Mar 12 '18 at 13:55

0 Answers0