Regex assistance

Discuss Autohotkey related topics here. Not a place to share code.
Forum rules
Discuss Autohotkey related topics here. Not a place to share code.
User avatar
kczx3
Posts: 1643
Joined: 06 Oct 2015, 21:39

Regex assistance

30 Nov 2019, 13:49

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.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Regex assistance

30 Nov 2019, 14:27

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*=>)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
kczx3
Posts: 1643
Joined: 06 Oct 2015, 21:39

Re: Regex assistance

01 Dec 2019, 20:29

@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
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Regex assistance

02 Dec 2019, 21:52

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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
kczx3
Posts: 1643
Joined: 06 Oct 2015, 21:39

Re: Regex assistance

03 Dec 2019, 20:56

Playing creating visual studio code extensions for AHK. So syntax highlighting is the start. Then maybe symbol definitions.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 31 guests