### RegExMatch on binary data from FileRead

Posted:

**28 May 2017, 12:25**How can RegExMatch be reliably performed on a binary file?

[EDIT:] The only useful link I've found on this:

[SOLVED] AHK_L unicode - binary search problem - Ask for Help - AutoHotkey Community

https://autohotkey.com/board/topic/7749 ... h-problem/

Code: Select all

```
q:: ;test RegExMatch on binary data
FileGetSize, vSize, % A_AhkPath
VarSetCapacity(vData1, vSize, 1)
FileRead, vData2, % "*c " A_AhkPath
DllCall("kernel32\RtlMoveMemory", Ptr,&vData1, Ptr,&vData2, UPtr,vSize)
vNeedle := "AutoHotkeyGUI"
vSizeNeedle := StrLen(vNeedle)*2
Loop, % Floor(vSizeNeedle/2)
{
vNum := NumGet(&vNeedle+0, A_Index*2-2, "UShort")
vNeedleRegEx .= "\x{" Format("{:04X}", vNum) "}"
}
MsgBox, % RegExMatch(vData1, vNeedleRegEx)*2-2 ;842752 first time, -2 afterwards
MsgBox, % RegExMatch(vData2, vNeedleRegEx)*2-2 ;-2
return
```

[SOLVED] AHK_L unicode - binary search problem - Ask for Help - AutoHotkey Community

https://autohotkey.com/board/topic/7749 ... h-problem/

Code: Select all

```
VarSetCapacity(v, 8, 1), NumPut(0x1020304000000000, v, 0, "int64") ; (reversed byte order)
MsgBox % (RegExMatch(v, "\x{3040}\x{1020}") - 1) * 2
```