1

I know this has a lot of similar Q&As here already, but I'm just not able to put it together from that.

What I want is to match particular function calls with a regular expression eg.:

Lib.myfunction( arg0, arg1,
                arg2, arg3 )

I'm looking for Lib.myFunction specifically, it doesn't have to be completely generic. Every such function call has extra empty line right after.

Little extra would be if it could be terminated with linebreak, then optional whitespace, then linebreak, because editors tend to add whitespace to align with text on preceding line.

Would you have ideas what should the regex look like?

2
  • I suppose you need \n\s*\n Mar 22 '19 at 18:41
  • 1
    \s inlcudes line breaks, but having [\t ]* instead doesn't match either
    – Pyjong
    Mar 22 '19 at 19:16
2
Lib\.myfunction\s*\(\s*\S+(?:,\s*\S+)*\s*\)

Explanation:

Lib\.myfunction     # literally
\s*                 # 0 or more spaces
\(                  # opening parenthesis
    \s*             # 0 or more spaces
    \S+             # 1 or more NON spaces
    (?:             # start non capturing group
        ,           # a comma
        \s*         # 0 or more spaces
        \S+         # 1 or more NON spaces
    )*              # end group, may appear 0 or more times
    \s*             # 0 or more spaces
\)                  # closing parenthesis

Demo

1
  • ahhh yes! YES! Thanks man!
    – Pyjong
    Mar 22 '19 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.