none
Unable To Use Regular Expression To Find Function Names RRS feed

  • Question

  • Hi,

    I am trying to create a regular expression to find function and procedure names without the static designation and the parameter list.  Sample source document:

    static function test

    static function test(i,j)

    function test

    function test(i,j)

    static procedure test

    static procedure test(i,j)

    procedure test

    procedure test(i,j)

    For each of the above samples, I would like only the word "test" to be found.

    Thanks


    Thursday, March 5, 2015 2:23 PM

Answers

  • From a reply on a different form, using the \k option yielded a solution:

    "^\h*(static\h+)?(procedure|function)\h+\K\w+"

    Thanks for your time

    Friday, March 6, 2015 3:07 PM

All replies

  • I suggest starting with this expression:

        ^\s*(static\s+)?(function|procedure)\s+(?<NAME>\w+)

    Programmatically, the name can be extracted from the group called “NAME”.

    The expression can be improved.

    • Marked as answer by gkeefe Friday, March 6, 2015 3:02 PM
    • Unmarked as answer by gkeefe Friday, March 6, 2015 3:02 PM
    Thursday, March 5, 2015 2:56 PM
  • From a reply on a different form, using the \k option yielded a solution:

    "^\h*(static\h+)?(procedure|function)\h+\K\w+"

    Thanks for your time

    Friday, March 6, 2015 3:07 PM
  • If what you want is just to capture the name of the functions or procedures then you could try something like:

    "(?<=(function|procedure))\s?(?<output>[A-Za-z]+)"

    Friday, March 6, 2015 6:04 PM