RegExMatch issue

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
iamgodxo
Posts: 16
Joined: 26 Oct 2023, 15:16

RegExMatch issue

Post by iamgodxo » 11 Jan 2024, 20:50

this script reads curl2.txt, uses RegExMatch, then displays result in msgbox:

Code: Select all

f1::
FileRead, output, curl2.txt
RegExMatch(output, "links"": \[\s*""(.*?)""\s*\]", result)
MsgBox, % result1
return
this is my curl2.txt file:

Code: Select all

	"links": [
		"https:\/\/real-debrid.com\/d\/ID"
	],
msgbox displays:

Code: Select all

https:\/\/real-debrid.com\/d\/ID
i want msgbox to display:

Code: Select all

https://real-debrid.com/d/ID
how can i revise my regexmatch command to achieve this?

sofista
Posts: 654
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: RegExMatch issue

Post by sofista » 11 Jan 2024, 21:40

It would be easier to delete the unwanted chars:

Code: Select all

f1::
FileRead, output, curl2.txt
RegExMatch(output, "links"": \[\s*""(.*?)""\s*\]", result)
MsgBox, % RegExReplace(result1, "\\")
return

iamgodxo
Posts: 16
Joined: 26 Oct 2023, 15:16

Re: RegExMatch issue

Post by iamgodxo » 11 Jan 2024, 22:01

i want to achieve my goal by using only the RegExMatch command

User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: RegExMatch issue

Post by mikeyww » 12 Jan 2024, 01:19

Code: Select all

#Requires AutoHotkey v1.1.35
s := "\\/([^\\\r\n""]+)", regex := "(https?:)\\/" s s s
FileRead output, curl2.txt
RegExMatch(output, regex, m), result1 := m1 "//" m2 "/" m3 "/" m4
MsgBox 64, Result, % result1
Return

iamgodxo
Posts: 16
Joined: 26 Oct 2023, 15:16

Re: RegExMatch issue

Post by iamgodxo » 12 Jan 2024, 04:40

i spent an entire day learning RegEx, i came to the conclusion that its best to use:

Code: Select all

StringReplace, link, result1, \,, all
updated script v1: (uses StringReplace to replace the backslashes) (simple/easy to understand)

Code: Select all

f1::
FileRead, output, curl2.txt
RegExMatch(output, "links"": \[\s*""(.*?)""\s*\]", result)
StringReplace, link, result1, \,, all
MsgBox, % link
return
updated script v2: (uses an expression with 5 capture groups, then combines them together in msgbox) (more complex/more concise)

Code: Select all

f2::
FileRead output, curl2.txt
RegExMatch(output, "(https:).(.).(.{16}).(..).(.{3})", x)
MsgBox, % x1 "" x2 "" x3 "" x4 "" x5
Return
thank you!

User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: RegExMatch issue

Post by mikeyww » 12 Jan 2024, 09:10

You could have reached the conclusion earlier by reading sofista's post! 8-) :)

Code: Select all

#Requires AutoHotkey v1.1.35
FileRead output, curl.txt
MsgBox 64, Result, % txt := url(output)
Return

url(str) {
 Return StrReplace(RegExReplace(str, "s).*(http[^""]+).*", "$1"), "\")
}

Post Reply

Return to “Ask for Help (v1)”