Match the body of a function using Regex

前端 未结 2 1359
暖寄归人
暖寄归人 2021-01-14 20:42

Given a dummy function as such:

public function handle()
{
  if (isset($input[\'data\']) {
    switch($data) {
      ...
    }
  } else {
    switch($data) {         


        
2条回答
  •  情书的邮戳
    2021-01-14 21:42

    This works to output header file (.h) out of inline function blocks (.c)

    Find Regular expression:

    (void\s[^{};]*)\n^\{($[^}$]*)\}$
    

    Replace with:

    $1;
    

    For input:

    void bar(int var)
    { 
        foo(var);
        foo2();
    }
    

    will output:

    void bar(int var);
    

    Get the body of the function block with second matched pattern :

    $2
    

    will output:

        foo(var);
        foo2();
    

提交回复
热议问题