-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathRegexLists.ahk
244 lines (231 loc) · 5.34 KB
/
RegexLists.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
; Written by AHK_User 2019-09-26
; Updated by AHK_User 2019-10-11
; Added Header parameter, if Header is "0", the parameter [parameter] will be interpreted as the number of the column you want to use in the filter
; Added List_DifferentValues(List1, List2)
/*
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
List1 =
(
Fruit,Price, Number
Apple,10,15
Banana,10,1
Kiwi,20,9
Pineapple,20,10
Avocado,30,20
Blackberry,10,10
Blueberry,40,10
Cherry,50,10
Cucumber,10,10
Guava,15,10
)
List2 =
(
Fruit,Price,Number
Apple,10,15
Pineapple,20,20
Mango, 30,10
Avocado,30,10
Blackberry,10 ,30
Cherry,50,10
Guava, 15, 15
Honeyberry,20,10
Lemon,10,20
Melon,20,10
)
MsgBox, % "DifferentValues:`n" List_DifferentValues(List1, List2)
MsgBox, % "List_Filter:`n" List_Filter(List1, "erry,")
MsgBox, % "List_FilterByParameter:`n" List_FilterByParameter(List1, "Price", "10")
MsgBox, % "List_CommonValues:`n" List_CommonValues(List1, List2)
MsgBox, % "List_CommonValuesByParameter:`n" List_CommonValuesByParameter(List1, List2, "Fruit")
return
*/
List_Filter(List1, SearchString, Type:="InStr", Header:="1"){
loop, Parse,List1, `n, `r
{
if (A_Index=Header){
List_Result := A_LoopField
Continue
}
if (Type="InStr"){
if (InStr(A_LoopField, SearchString)){
List_Result .= (List_Result="") ? (A_LoopField) : ("`n" A_LoopField)
}
}
else if (Type="!InStr"){
if (!InStr(A_LoopField, SearchString)){
List_Result .= (List_Result="") ? (A_LoopField) : ("`n" A_LoopField)
}
}
else if (Type="RegExMatch"){
if (RegExMatch(A_LoopField, SearchString)){
List_Result .= (List_Result="") ? (A_LoopField) : ("`n" A_LoopField)
}
}
else if (Type="!RegExMatch"){
if (!RegExMatch(A_LoopField, SearchString)){
List_Result .= (List_Result="") ? (A_LoopField) : ("`n" A_LoopField)
}
}
else {
return false
}
}
return List_Result
}
List_FilterByParameter(List1, Parameter, SearchString, Type:="equal", Delimiter:="`,", OmitChars=" ", Header:="1"){
if(Header:="0"){
Parameter_Index := Parameter
}
loop, Parse,List1, `n, `r
{
if (A_Index=Header){
List_Result := A_LoopField
loop, Parse,A_LoopField, %Delimiter%, %OmitChars%
{
if (A_LoopField=Parameter){
Parameter_Index :=A_Index
Continue
}
}
}
Arr_Value := StrSplit(A_LoopField, Delimiter, OmitChars)
if (Type="equal"){
if (Arr_Value[Parameter_Index]=SearchString){
List_Result .= (List_Result="") ? (A_LoopField) : ("`n" A_LoopField)
}
}
else if (Type="InStr"){
if (InStr(Arr_Value[Parameter_Index], SearchString)){
List_Result .= (List_Result="") ? (A_LoopField) : ("`n" A_LoopField)
}
}
else if (Type="!InStr"){
if (!InStr(Arr_Value[Parameter_Index], SearchString)){
List_Result .= (List_Result="") ? (A_LoopField) : ("`n" A_LoopField)
}
}
else if (Type="RegExMatch"){
if (RegExMatch(Arr_Value[Parameter_Index], SearchString)){
List_Result .= (List_Result="") ? (A_LoopField) : ("`n" A_LoopField)
}
}
else if (Type="!RegExMatch"){
if (!RegExMatch(Arr_Value[Parameter_Index], SearchString)){
List_Result .= (List_Result="") ? (A_LoopField) : ("`n" A_LoopField)
}
}
else {
return false
}
}
return List_Result
}
List_CommonValues(List1, List2, Header:="1"){
Arr_list1 := {}
loop, Parse,List1, `n, `r
{
if (A_LoopField=""){
Continue
}
Arr_list1[A_LoopField]:=1
}
List_Result :=""
loop, Parse,List2, `n, `r
{
if (A_Index=Header){
if(Arr_list1[A_LoopField]=1){
List_Result .= A_LoopField
}
Continue
}
if(Arr_list1[A_LoopField]=1){
List_Result .= (List_Result="") ? (A_LoopField) : ("`n" A_LoopField)
}
}
return List_Result
}
List_CommonValuesByParameter(List1, List2, Parameter, Delimiter:="`,", OmitChars=" ", Header:="1"){
Arr_list1 := {}
Arr_list2 := {}
if(Header:="0"){
Parameter_Index := Parameter
}
loop, Parse,List1, `n, `r
{
if (A_Index=Header){
loop, Parse,A_LoopField, %Delimiter%, %OmitChars%
{
if (A_LoopField=Parameter){
Parameter_Index :=A_Index
List_Result := Parameter
Continue
}
}
Continue
}
Arr_Value := StrSplit(A_LoopField, Delimiter, OmitChars=" ")
if (Arr_Value[Parameter_Index]=""){
Continue
}
Arr_list1[Arr_Value[Parameter_Index]]:=1
}
loop, Parse,List2, `n, `r
{
if (A_Index=Header){
loop, Parse,A_LoopField, %Delimiter% ,
{
if (A_LoopField=Parameter){
Parameter_Index :=A_Index
Continue
}
}
}
Arr_Value2 := StrSplit(A_LoopField, Delimiter)
if (Arr_Value2[Parameter_Index]=""){
Continue
}
if(Arr_list1[Arr_Value2[Parameter_Index]]=1){
List_Result .= "`n" Arr_Value2[Parameter_Index]
}
}
return List_Result
}
List_DifferentValues(List1, List2, Header:="1"){
Arr_list1 := {}
loop, Parse,List1, `n, `r
{
if (A_LoopField=""){
Continue
}
Arr_list1[A_LoopField]:=1
}
Arr_list2 := {}
loop, Parse,List2, `n, `r
{
if (A_LoopField=""){
Continue
}
Arr_list2[A_LoopField]:=1
}
List_Result :=""
loop, Parse,List2, `n, `r
{
if (A_Index=Header){
List_Result .= A_LoopField
Continue
}
if(Arr_list1[A_LoopField]!=1){
List_Result .= (List_Result="") ? (A_LoopField) : ("`n" A_LoopField)
}
}
loop, Parse,List1, `n, `r
{
if (A_Index=Header){
Continue
}
if(Arr_list2[A_LoopField]!=1){
List_Result .= (List_Result="") ? (A_LoopField) : ("`n" A_LoopField)
}
}
return List_Result
}