Page 1 of 1

Regex assistance

Posted: 30 Nov 2019, 13:49
by kczx3
Could anyone tell me how I might be able to fix the issue in the following regex sample?

https://regex101.com/r/t9Wxs2/1

It is matching the initial method call when I just want it to match the ( ) of the fat arrow expression. Regex is not my strong suit unfortunately.

Re: Regex assistance

Posted: 30 Nov 2019, 14:27
by jeeswg
I think you just want \K, so, the info before the \K is used for searching, but not output in the result.
Also, you could use [^(] instead of ., to select consecutive characters, but exclude open parentheses.

Code: Select all

before/after/after:
\b\w+\((.*)\)(?=\s*=>)
\b\w+\K\((.*)\)(?=\s*=>)
\(([^(]*)\)(?=\s*=>)

Re: Regex assistance

Posted: 01 Dec 2019, 20:29
by kczx3
@jeeswg Thanks, that does help. My conflict now is that it matches too soon if the function call has a string with a close parenthesis in it or a fat arrow function... Seems like I can't get the right combination of commands here.

Notice how the last line isn't properly matching till the end.
https://regex101.com/r/t9Wxs2/2

Re: Regex assistance

Posted: 02 Dec 2019, 21:52
by jeeswg
Hmm, there's a problem because there's a literal parenthesis inside a string.

At that point I might consider properly parsing the string, i.e. identifying parentheses, commas, quotes (the starts/ends of strings) etc. Which I do here:

DllCall converter/cleaner (e.g. x32 to x64/x32 two-way compatible) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=31365

Btw what is your overall aim? Cheers.

Re: Regex assistance

Posted: 03 Dec 2019, 20:56
by kczx3
Playing creating visual studio code extensions for AHK. So syntax highlighting is the start. Then maybe symbol definitions.