Regex question Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kauan014
Posts: 55
Joined: 18 Feb 2021, 20:03

Regex question

08 Nov 2021, 19:35

I'm testing this regex here:
https://regex101.com/r/axEy74/1

But in ahk it's not working, trying to understand why?

Code: Select all

text = 
(
   VDrraWVFCyK="ERQvISDRKgB"
   kklTAmMEjW="PIWZpuaMfxJS"
   jHOLoOPdoWCu="buUFpZGtRaGI"
   ywVKKhsGGuvXiVZ="qhhrGKtMdrEoKkv"
   JmZRlQTmZY="zsNASCuTtS"
   qlvNbWFduNzaOhx="IMylrX"     ff"jabRua"
   cpeurSWuaTObUE="EIjaSkudBf"
   VDVaxaYemHs="cVMYBYouRi"
   TyhbGUMxYMOmu="fgvfdgsds"
   wxNsETYyPnsol="fdfddsds: "
   QTlJbdLRkY=""   
)

regex   = ms)="(.*)"( |$)
text   := RegExReplace(text, regex, "=" "$1")
Im trying to remove the first and last " after the first = in each line.
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Regex question

08 Nov 2021, 19:43

Try:

Code: Select all

text := RegExReplace(text, "m`a)=.*?\K""(.*)""", "$1")
kauan014
Posts: 55
Joined: 18 Feb 2021, 20:03

Re: Regex question

08 Nov 2021, 20:01

@mikeyww thank you, your regex does help, what i was doing wrong on mine?
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Regex question  Topic is solved

08 Nov 2021, 20:08

Just two things:

1. Option s means that the dot matches all characters including newlines-- not what you wanted here, since you are matching line by line.
2. Option `a means that `n (and some other sequences) is recognized as a newline in addition to `r`n.

Demo:

Code: Select all

text =
(
1
2
)
MsgBox, 64, Length, % StrLen(text)
MsgBox, 64, Second character is line feed, % Asc(SubStr(text, 2))
Explained: Regular expressions

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Kintaro-OEx, Mateusz53, mikeyww, MrHue and 255 guests