Search code examples
regexsublimetext3sublimetext

How to override entity.name.function using regex?


Syntax my functions: return_type func_name(parameters)

I need to get only func_name. I used regex

'(?:(String|Array|Map|Bool|bool|exception|string|Int|Float|Variant|Object|Message|message|void))\s({{identifier}}(?=\s*\())' but i get back return_type + func_name. If i used ?! i get a function call.

func_name(arg), example: ToString("").

{{identifier}} = \b[[:alpha:]_][[:alnum:]_]*\b

Thanks all!


Solution

  • Use

    (?:String|Array|Map|Bool|bool|exception|string|Int|Float|Variant|Object|Message|message|void)\s+\K[[:alpha:]_][[:alnum:]_]*(?=\s*\()
    

    See proof.

    The (?:String|Array|Map|Bool|bool|exception|string|Int|Float|Variant|Object|Message|message|void) matches types, \s+ matches one or more whitespace characters, \K will omit the matched text, [[:alpha:]_][[:alnum:]_]* will match a function name if there are any whitespaces + ( following it.