RegExReplace not working like in Notepad++ Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
daniel
Posts: 17
Joined: 23 May 2016, 22:41

RegExReplace not working like in Notepad++

22 Jul 2019, 13:39

Hello, I am trying to get RegExReplace to work.

Here is my script:

Code: Select all

StringLeft := "leftleftleftleftleftleftleftleftleftleft"


Output .= RegExReplace(StringLeft, "(left(?:(?!left).)*)left((?:(?!left).)*)", "\1right\2")

MsgBox % Output

Clipboard := Output
If I use this in Notepad++, namely (left(?:(?!left).)*)left((?:(?!left).)*) for search and \1right\2 for replacement, I get leftleftleftleftleftleftleftleftleftleft. But it doesn't work for me in AHK.

Instead, I get \1right\2\1right\2\1right\2\1right\2\1right\2. I've put up this RegEx on RegEx 101 at https regex101.com /r/z0bH8g/1/. Broken Link for safety
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

Re: RegExReplace not working like in Notepad++  Topic is solved

22 Jul 2019, 13:50

Try using dollar symbol. See below...

Code: Select all

RegExReplace(StringLeft, "(left(?:(?!left).)*)left((?:(?!left).)*)", "$1right$2")

https://www.autohotkey.com/docs/commands/RegExReplace.htm#BackRef

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, Google [Bot], javic, peter_ahk and 77 guests