RegEx works in v1 but not v2 Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

RegEx works in v1 but not v2

28 Jan 2021, 08:24

This regular expression works in a v1 RegExReplace but not in v2 - any pointers as to what's wrong please?

Code: Select all

Error:  Missing space or operator before this.

Specifically: "configuration"").*,?("".*?\.executePath"": ).*?(""C:.*?" var "(.*?)?\.exe"").*"

--->	063: RegEx := ".*(?<=\n\t{2}""configuration"").*,?("".*?\.executePath"": ).*?(""C:.*?" var "(.*?)?\.exe"").*"
User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

Re: RegEx works in v1 but not v2

28 Jan 2021, 08:47

The Substitution demonstrates the goal of the RegExReplace.
https://regex101.com/r/UxR5cn/1
User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

Re: RegEx works in v1 but not v2

28 Jan 2021, 10:35

A simplified demo to return "line3" "line5".

Code: Select all

multiLineVar := "
(LTrim
    line0
    ""line1""
    line2
    ""line3""
    line4
    ""line5""
    line6
)"
RegEx := ".*(?<=\n""line1"").*?(""line3"").*?(""line5"").*"
result := RegExReplace(multiLineVar, RegEx, "$1 $2")
MsgBox %result% ;v1
;MsgBox result ;v2
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: RegEx works in v1 but not v2

28 Jan 2021, 11:16

v1: ""
v2: `"

RegEx := ".*(?<=\n\t{2}`"configuration`").*,?(`".*?\.executePath`": ).*?(`"C:.*?" var "(.*?)?\.exe`").*"
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: RegEx works in v1 but not v2

28 Jan 2021, 11:42

consider enclosing strings in single/double quotes(depending on whichever makes the most sense) to avoid having to unnecessarily escape characters
RegEx := '.*(?<=\n\t{2}"configuration").*,?(".*?\.executePath": ).*?("C:.*?' var '(.*?)?\.exe").*'
User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

Re: RegEx works in v1 but not v2

28 Jan 2021, 11:59

@HotKeyIt & @swagfag

I'm unable to test in the original script as I'm still working through other changes needed, but neither suggestion works for the simplified demo I included.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: RegEx works in v1 but not v2  Topic is solved

28 Jan 2021, 12:29

Code: Select all

multiLineVar := "
(
    line0
    "line1"
    line2
    "line3"
    line4
    "line5"
    line6
)"
RegEx := 's).*(?<=\n"line1").*?("line3?").*?("line5").*'
result := RegExReplace(multiLineVar, RegEx, "$1 $2")
MsgBox result ;v2
User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

Re: RegEx works in v1 but not v2

28 Jan 2021, 14:33

@HotKeyIt Thanks for sorting out the quoting/escaping issue, but I notice that v2 requires the single-line modifier, whereas it wasn't required in v1, not in the above demo at least.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: RegEx works in v1 but not v2

28 Jan 2021, 16:05

Yes, not sure why it works in v1, as I understand it should not.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Jeffmuvans, Umbracinis and 35 guests