forked from Paris/AutoHotkey-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrep.ahk
30 lines (26 loc) · 1.01 KB
/
grep.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
Function: grep
Sets the output variable to all the entire or specified subpattern matches and returns their offsets within the haystack.
Parameters:
h - haystack
n - regex
v - output variable (ByRef)
s - (optional) starting position (default: 1)
e - (optional) subpattern to save in the output variable, where 0 is the entire match (default: 0)
d - (optional) delimiter - the character that seperates multiple values (default: EOT (0x04))
Returns:
The position (or offset) of each entire match.
Remarks:
Since multiple values are seperated with the delimiter any found within the haystack will be removed.
License:
- Version 2.0 <http://www.autohotkey.net/~polyethene/#grep>
- Dedicated to the public domain (CC0 1.0) <http://creativecommons.org/publicdomain/zero/1.0/>
*/
grep(h, n, ByRef v, s = 1, e = 0, d = "") {
v =
StringReplace, h, h, %d%, , All
Loop
If s := RegExMatch(h, n, c, s)
p .= d . s, s += StrLen(c), v .= d . (e ? c%e% : c)
Else Return, SubStr(p, 2), v := SubStr(v, 2)
}