Page 1 of 1
RegExMatch issue
Posted: 11 Jan 2024, 20:50
by iamgodxo
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:
i want msgbox to display:
how can i revise my regexmatch command to achieve this?
Re: RegExMatch issue
Posted: 11 Jan 2024, 21:40
by sofista
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
Re: RegExMatch issue
Posted: 11 Jan 2024, 22:01
by iamgodxo
i want to achieve my goal by using only the RegExMatch command
Re: RegExMatch issue
Posted: 12 Jan 2024, 01:19
by mikeyww
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
Re: RegExMatch issue
Posted: 12 Jan 2024, 04:40
by iamgodxo
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!
Re: RegExMatch issue
Posted: 12 Jan 2024, 09:10
by mikeyww
You could have reached the conclusion earlier by reading sofista's post!
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"), "\")
}