-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathStRegX.ahk
35 lines (34 loc) · 1.29 KB
/
StRegX.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
31
32
33
34
35
stRegX(h,BS="",BO=1,BT=0, ES="",ET=0, ByRef N="") {
/* modified version: searches from BS to " "
h = Haystack
BS = beginning string
BO = beginning offset
BT = beginning trim, TRUE or FALSE
ES = ending string
ET = ending trim, TRUE or FALSE
N = variable for next offset
*/
;~ BS .= "(.*?)\s{3}"
rem:="^[OPimsxADJUXPSC(\`n)(\`r)(\`a)]+\)" ; All the possible regexmatch options
pos0 := RegExMatch(h,((BS~=rem)?"Oim"BS:"Oim)"BS),bPat,((BO)?BO:1))
/* Ensure that BS begins with at least "Oim)" to return [O]utput, case [i]nsensitive, and [m]ultiline searching
Return result in "bPat" (beginning pattern) object
If (BO), start at position BO, else start at 1
*/
pos1 := RegExMatch(h,((ES~=rem)?"Oim"ES:"Oim)"ES),ePat,pos0+bPat.len())
/* Ensure that ES begins with at least "Oim)"
Resturn result in "ePat" (ending pattern) object
Begin search after bPat result (pos0+bPat.len())
*/
bmod := (BT) ? bPat.len() : 0
emod := (ET) ? 0 : ePat.len()
N := pos1+emod
/* Final position is start of ePat match + modifier
If (ET), add nothing, else add ePat.len()
*/
return substr(h,pos0+bmod,(pos1+emod)-(pos0+bmod))
/* Start at pos0
If (BT), add bPat.len(), else stay at pos0 (will include BS in result)
substr length is position of N (either pos1 or include ePat) less starting pos0
*/
}