Can regular expressions be used to match nested pa

2018-12-30 23:36发布

Is it possible to write a regular expression that matches a nested pattern that occurs an unknown number of times? For example, can a regular expression match an opening and closing brace when there are an unknown number of open/close braces nested within the outer braces?

For example:

public MyMethod()
{
  if (test)
  {
    // More { }
  }

  // More { }
} // End

Should match:

{
  if (test)
  {
    // More { }
  }

  // More { }
}

13条回答
笑指拈花
2楼-- · 2018-12-31 00:39

Yes, if it is .NET RegEx-engine. .Net engine supports finite state machine supplied with an external stack. see details

查看更多
登录 后发表回答