-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathhelp_use_variables_dark.html
More file actions
1226 lines (1099 loc) · 49.1 KB
/
help_use_variables_dark.html
File metadata and controls
1226 lines (1099 loc) · 49.1 KB
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>MultiReplace Use Variables Option</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
/* Dark Mode Base Styles */
body.dark-mode { background: #121212; color: #ccc; }
/* Header and Footer Styles */
body.dark-mode header,
body.dark-mode footer { background: #1e1e1e; color: #ddd; border-color: #333; }
/* Link Styles */
body.dark-mode a { color: #4ea8de; }
body.dark-mode a:link { color: #89b4ff; }
body.dark-mode a:visited { color: #89b4ff; }
/* Navigation Link Styles in Dark Mode */
body.dark-mode nav.pagenav {
background-color: #333;
padding: 10px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
margin-bottom: 20px;
}
body.dark-mode nav.pagenav a { color: #89b4ff; }
body.dark-mode nav.pagenav a:visited { color: #89b4ff; }
body.dark-mode nav.pagenav a:hover { text-decoration: underline; }
/* Main Content and Article Styling */
body.dark-mode main,
body.dark-mode article { background: #242424; }
/* Footer Links */
body.dark-mode footer a[rel=license],
body.dark-mode footer a[rel=license] img { color: #888; }
/* Text Elements */
body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3,
body.dark-mode p { color: #e0e0e0; }
/* Interactive Elements */
body.dark-mode #fontdown,
body.dark-mode #fontup { background: #333; color: #fff; }
body.dark-mode #fontdown:hover,
body.dark-mode #fontup:hover { background: #444; color: #eee; }
/* Additional UI Components */
body.dark-mode main article section { background: #333; border-color: #444; }
body.dark-mode main article section.note { background: #2b2b2b; color: #ddd; }
/* Table Styling */
body.dark-mode table.optionsTable { background: #333; color: #ddd; }
body.dark-mode table.optionsTable th,
body.dark-mode table.optionsTable td { background: #2b2b2b; color: #ccc; }
body.dark-mode table.optionsTable th { background: #333; }
body.dark-mode table.optionsTable tr:hover { background: #3a3a3a; }
/* Miscellaneous Adjustments */
body.dark-mode span.mnemonic { background: #4ea8de; color: #121212; }
body.dark-mode ul, body.dark-mode li { color: #ddd; }
/* Dark Mode Footer Text Styles */
body.dark-mode #foottext { flex: 1; margin: 0 1em; text-align: center; color: #ddd; }
body.dark-mode #foottext a { white-space: nowrap; text-decoration: none; color: #4ea8de; }
body.dark-mode #foottext a:hover { text-decoration: underline; color: #62d1c3; }
body.dark-mode #foottext.linklist a:link { color: #89b4ff; }
body.dark-mode #foottext.linklist a:visited { color: #c678dd; }
body.dark-mode code {
font-family: 'Fira Code', 'Consolas', monospace;
color: #abb2bf;
background-color: #282c34;
padding: 6px 8px;
border-radius: 5px;
border: 1px solid #3a3c43;
font-weight: 600;
font-size: 0.9em;
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
display: inline-block;
margin: 0 2px;
vertical-align: middle;
line-height: 1.4;
}
/* Base Styles */
html, body {margin: 0; padding: 0; width: 100%; height: 100%;}
body {display: flex; flex-direction: column; font: 1em Calibri, Tahoma, sans-serif;}
header {padding: 0; width: 100%; display: flex; flex-direction: row; justify-content: space-around;}
header {border-style: none none solid none; border-width: 0 0 2px 0;}
header {font-size: min(5vw,10vh,1.75rem); font-weight: bold;}
footer {padding: 4px 0; width: 100%; display: flex; flex-direction: row; align-items: center; font-size: medium;}
footer {border-style: solid none none none; border-width: 2px 0 0 0;}
footer a[rel=license] {padding: 0 8px; text-decoration: none;}
footer a[rel=license] img {border: none;}
#foottext {flex: 1; margin: 0 1em; text-align: center;}
#foottext a {white-space: nowrap; text-decoration: none; color: inherit; }
#foottext a:hover {text-decoration: underline;}
#foottext.linklist a:link {color: #00c;}
#foottext.linklist a:visited {color: #900;}
#fontdown, #fontup {margin: 0 8px; padding: 0; height: 28px; width: 48px; text-align: center; display: none;}
#fontdown, #fontup {color: #000; border: none; border-radius: 15%/20%; cursor: pointer;}
#fontdown, #fontup {background: transparent;}
#fontdown:hover,
#fontup:hover {background: #333; color: #fff;}
#fontdown {font: inherit; font-size: 13px;}
#fontup {font: inherit; font-size: 19px; line-height: 1.0;}
main {flex: 1; overflow: auto;}
article {padding: 0 1em; line-height: 1.4;}
p {margin: 0; padding: 0;}
p + p {margin: .5em 0 0 0; padding: 0;}
h1 {line-height: 1.25; margin: .5em 0 0 0;}
h1 {font-size: 1.5rem; text-align: center; font-weight: bold; font-style: normal; padding: 0;}
h2 {font-size: 1.3rem; text-align: left; font-weight: bold; font-style: normal; padding: 0; margin: 0;}
h3 {font-size: 1.2rem; text-align: left; font-weight: bold; font-style: normal; padding: 0; margin: 0; }
main a {white-space: nowrap; text-decoration: none;}
main a:link {color: #00c;}
main a:visited {color: #00c;}
main a:hover {text-decoration: underline;}
@media (max-width: 480px) {
main a {white-space: normal;}
#foottext a {white-space: normal;}
}
main article section {border-style: none; border-width: 0; padding: 0 1em .3em 1em; background: #eee;}
main article section {margin: 1.25rem 0 .4rem 0;}
main article section h2 {border-style: none none solid none; border-width: 0 0 1px 0;}
main article section h2 {margin: 0 0 .3em -6px; padding: .2em 0 .2em 6px;}
main article section h3 {margin: .75em 0 .2em 0; padding: .2em 0 .1em 0; line-height: 1.2; }
main article h1+section {margin-top: .75rem;}
main article h1+p {margin-top: .6em;}
main article section+p {margin-top: .75em;}
main article section >
p:first-child {margin-top: .3em;}
main article section.note {font-size: .85em; border-style: solid; border-width: 3px 1px 1px 6px; padding: 0 6px;}
body h1 {margin: 0;}
body .pagenav {font-weight: bold; text-align: left; margin: .5em .5em 0 .5em; line-height: 1.6; background: #eee;}
body .pagenav a {margin: 0 .5em; white-space: nowrap;}
@media (min-width: 640px) {
body main {display: flex; flex-direction: row; padding: 0;}
body .pagenav {padding: .5em 0 0 0; margin: 1.25em 1em .4em;}
body .pagenav {white-space: pre;}
body article {flex: 1; overflow: auto; padding: 0 1em 0 0;}
body h1 {margin-top: .5em;}
}
body #centershortlines ~ article h1 {max-width: calc(32em + 12px);}
body #centershortlines ~ article section {max-width: 58em;}
p.subsub {margin-left: 1.5em;}
table.justAlign {border: none; margin: 0; border-collapse: collapse;}
table.justAlign td {border:none; padding: 0; font: inherit;}
table.justAlign td+td {padding: 0 0 0 1em;}
ul {margin: 0 0 .5em 0;}
ul li {margin: .25em 0;}
span.mnemonic {color: #fff; background: #000; padding: 0 .2em; border-radius: .2em; font-size: .9em; font-weight: bold; display: inline-block;}
body {color: #000; background: #d0d0d0; line-height: 1.4;}
* {border-color: #999;}
#centershortlines {width: calc((100vw - (13.5em + 48em + 2em + 24px)) / 2);}
code {
font-family: 'Fira Code', 'Consolas', monospace;
color: #333;
background-color: #eef2f5;
padding: 6px 8px;
border-radius: 5px;
border: 1px solid #d1d6da;
font-weight: 600;
font-size: 0.9em;
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1);
display: inline-block;
margin: 0 2px;
vertical-align: middle;
line-height: 1.4;
}
table.optionsTable {
border-collapse: separate;
border-spacing: 0;
width: 100%;
margin: 1em auto;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
background: white;
border-radius: 8px;
overflow: hidden;
}
table.optionsTable th,
table.optionsTable td {
padding: .8em 1em;
text-align: left;
vertical-align: middle;
border-bottom: 2px solid #ccc;
box-shadow: inset 0 -1px 0 #ccc;
}
table.optionsTable th {
background-color: #ddd;
color: #333;
font-weight: 600;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
table.optionsTable tr:last-child th,
table.optionsTable tr:last-child td {
border-bottom: none;
}
table.optionsTable tr:hover {
background-color: #ececec;
}
table .optionsTable .group {
background-color: #d0d0d0;
color: #333;
text-align: center;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
nav.pagenav {
background-color: #eee;
padding: 5px;
border-radius: 8px;
margin-bottom: 20px;
display: flex;
flex-direction: column;
align-items: flex-start;
}
nav.pagenav a {
color: #00c;
text-decoration: none;
margin: 0;
padding: 2px 0;
}
nav.pagenav a:hover {
text-decoration: underline;
}
nav.pagenav .sub-item {
margin-left: 15px;
font-size: 0.95em;
}
body.dark-mode nav.pagenav {
background-color: #333;
}
body.dark-mode nav.pagenav a {
color: #89b4ff;
}
body.dark-mode nav.pagenav a:hover {
color: #62d1c3;
}
body.dark-mode nav.pagenav .sub-item {
color: #89b4ff;
}
</style>
<script>
var isDarkModeEnabled = true; // Set this variable to true or false to activate or deactivate DarkMode
function doPageLoad() {
if (document.getElementById("fontdown")) {
document.getElementById("fontdown").style.display = "inline-block";
document.getElementById("fontup").style.display = "inline-block";
if (window.localStorage) {
var n = localStorage.getItem("ColumnsPlusPlusFontSize");
if (!isNaN(n) && n >= 9 && n <= 40) {
document.documentElement.style.fontSize = n + "px";
}
}
}
}
function setFontDown() {
var n = parseFloat(window.getComputedStyle(document.documentElement).fontSize);
if (n > 9) --n;
document.documentElement.style.fontSize = n + "px";
if (window.localStorage) localStorage.setItem("ColumnsPlusPlusFontSize", n);
}
function setFontUp() {
var n = parseFloat(window.getComputedStyle(document.documentElement).fontSize);
if (n < 40) ++n;
document.documentElement.style.fontSize = n + "px";
if (window.localStorage) localStorage.setItem("ColumnsPlusPlusFontSize", n);
}
function checkDarkMode() {
if (isDarkModeEnabled) {
document.body.classList.add('dark-mode');
console.log("Dark Mode On");
} else {
console.log("Dark Mode Off");
}
}
document.addEventListener('DOMContentLoaded', function() {
console.log("Document loaded");
checkDarkMode();
});
</script>
</head>
<body onload="doPageLoad()">
<header>MultiReplace: "Use Variables" Feature Guide</header>
<main>
<div id="centershortlines"></div>
<nav class="pagenav">
<a href="#Introduction">Introduction</a>
<a href="#QuickStart">Quick Start</a>
<a href="#Variables">Variables</a>
<a href="#AvailableFunctions">Available Functions</a>
<a href="#Commands">Command Reference</a>
<a href="#setstrorcalc" class="sub-item">set()</a>
<a href="#condcondition-trueval-falseval" class="sub-item">cond()</a>
<a href="#varsvariable1value1-variable2value2-" class="sub-item">vars()</a>
<a href="#lvarsfilepath" class="sub-item">lvars()</a>
<a href="#lkpkey-hpath-inner" class="sub-item">lkp()</a>
<a href="#fmtnnum-maxdecimals-fixeddecimals" class="sub-item">fmtN()</a>
<a href="#lcmdpath" class="sub-item">lcmd()</a>
<a href="#StringHelpers">String Formatting Helpers</a>
<a href="#preload-variables--helpers">Preload Variables & Helpers</a>
<a href="#Operators">Operators</a>
<a href="#IfThenLogic">If-Then Logic</a>
<a href="#DebugMode">Debug Mode</a>
<a href="#FurtherFunctions">Math & String Functions</a>
<a href="#Examples">Examples</a>
</nav>
<article>
<section id="Introduction">
<h2>Introduction</h2>
<p>
Enable the <strong>Use Variables</strong> option to enhance replacements with calculations and logic based on the matched text. This feature lets you create dynamic replacement patterns, handle conditions, and produce flexible outputs—all configured directly in the Replace field. This functionality relies on the <a href="https://www.lua.org/">Lua engine</a>.
</p>
</section>
<hr>
<section id="QuickStart">
<h2>Quick Start: Use Variables</h2>
<ol>
<li>
<strong>Enable "Use Variables"</strong><br>
Check the "<strong>Use Variables</strong>" option in the Replace interface.
</li>
<li>
<strong>Use a Command</strong><br><br>
<p><strong>Option 1:</strong> <a href="#setstrorcalc"><code>set(...)</code></a> → Directly replaces with a value or calculation.</p>
<ul>
<li><strong>Find</strong>: <code>(\d+)</code></li>
<li><strong>Replace</strong>: <code>set(tonum(CAP1) * 2)</code></li>
<li><strong>Result</strong>: Doubles numbers (e.g., <code>50</code> → <code>100</code>).</li>
</ul>
<em>(Enable 'Regular Expression' in 'Search Mode' to use <code>(\d+)</code> as a capture group.)</em>
<p><strong>Option 2:</strong> <a href="#condcondition-trueval-falseval"><code>cond(...)</code></a> → Conditional replacement.</p>
<ul>
<li><strong>Find</strong>: <code>word</code></li>
<li><strong>Replace</strong>: <code>cond(CNT==1, "FirstWord")</code></li>
<li><strong>Result</strong>: Changes only the <strong>first</strong> occurrence of "word" to "FirstWord".</li>
</ul>
</li>
<li>
<strong>Use Basic Variables:</strong>
<ul>
<li><strong><code>CNT</code></strong>: Inserts the current match number (e.g., "1" for the first match, "2" for the second).</li>
<li><strong><code>CAP1</code>, <code>CAP2</code>, etc.:</strong> Holds captured groups when Regex is enabled.<br>
<blockquote>
<strong>Capture Groups:</strong><br>
With a regex in parentheses <code>(...)</code>, matched text is stored in <code>CAP</code> variables (e.g., <code>(\d+)</code> in <code>Item 123</code> stores <code>123</code> in <code>CAP1</code>). For more details, refer to regex documentation.
</blockquote>
</li>
</ul>
See the <a href="#Variables">Variables Overview</a> for a complete list.
</li>
</ol>
</section>
<hr>
<section id="Variables">
<h2>Variables Overview</h2>
<table class="optionsTable">
<tr>
<th>Variable</th>
<th>Description</th>
</tr>
<tr>
<td><strong>CNT</strong></td>
<td>Count of the detected string.</td>
</tr>
<tr>
<td><strong>LCNT</strong></td>
<td>Count of the detected string within the line.</td>
</tr>
<tr>
<td><strong>LINE</strong></td>
<td>Line number where the string is found.</td>
</tr>
<tr>
<td><strong>LPOS</strong></td>
<td>Relative character position within the line.</td>
</tr>
<tr>
<td><strong>APOS</strong></td>
<td>Absolute character position in the document.</td>
</tr>
<tr>
<td><strong>COL</strong></td>
<td>Column number where the string was found (CSV-Scope option selected).</td>
</tr>
<tr>
<td><strong>MATCH</strong></td>
<td>Contains the text of the detected string, in contrast to <code>CAP</code> variables which correspond to capture groups in regex patterns.</td>
</tr>
<tr>
<td><strong>FNAME</strong></td>
<td>Filename or window title for new, unsaved files.</td>
</tr>
<tr>
<td><strong>FPATH</strong></td>
<td>Full path including the filename, or empty for new, unsaved files.</td>
</tr>
<tr>
<td><strong>CAP1</strong>, <strong>CAP2</strong>, ...</td>
<td>Equivalents to regex capture groups, designed for use in the 'Use Variables' environment. Always strings; use <code>tonum(CAP1)</code> for calculations. Note: Standard counterparts (<code>$1</code>, <code>$2</code>, ...) cannot be used in this environment.</td>
</tr>
</table>
<p><strong>Notes:</strong></p>
<ul>
<li><code>FNAME</code> and <code>FPATH</code> are updated for each file processed by <code>Replace All in All Open Docs</code> and <code>Replace All in Files</code>. This ensures that variables always refer to the file currently being modified.</li>
<li><strong>String Variables:</strong> <code>MATCH</code> and <code>CAP</code> variables are always strings. For calculations, use <code>tonum(CAP1)</code>. Both dot (.) and comma (,) are recognized as decimal separators. Thousands separators are not supported.</li>
</ul>
</section>
<br>
<section id="AvailableFunctions">
<h2>Available Functions</h2>
<p>The following functions are available for use in the Replace field:</p>
<table class="optionsTable">
<tr>
<th>Function</th>
<th>Description</th>
<th>Example</th>
</tr>
<tr>
<td><code>set(v)</code></td>
<td>Returns <code>v</code> as the replacement string. If <code>v</code> is <code>nil</code>, the replacement is skipped.</td>
<td><code>set("Value: " .. CNT)</code></td>
</tr>
<tr>
<td><code>cond(c, t, f)</code></td>
<td>If <code>c</code> is true, returns <code>t</code>. If false, returns <code>f</code>. If <code>f</code> is omitted, skips replacement on false.</td>
<td><code>cond(CNT > 5, "Over 5")</code></td>
</tr>
<tr>
<td><code>fmtN(n, d, f)</code></td>
<td>Formats number <code>n</code> with <code>d</code> decimal places and optional fixed flag <code>f</code>.</td>
<td><code>fmtN(math.pi, 2)</code> → <code>"3.14"</code></td>
</tr>
<tr>
<td><code>trim(s)</code></td>
<td>Removes leading and trailing whitespace from string <code>s</code>.</td>
<td><code>trim(" abc ")</code> → <code>"abc"</code></td>
</tr>
<tr>
<td><code>tonum(s)</code></td>
<td>Converts string <code>s</code> to number. Accepts both dot (.) and comma (,) as decimal separator.</td>
<td><code>tonum(CAP1) * 2</code></td>
</tr>
<tr>
<td><code>padL(s, w, c)</code></td>
<td>Pads string <code>s</code> on the <strong>left</strong> to width <code>w</code> with char <code>c</code>.</td>
<td><code>padL(CNT, 3, "0")</code> → <code>"001"</code></td>
</tr>
<tr>
<td><code>padR(s, w, c)</code></td>
<td>Pads string <code>s</code> on the <strong>right</strong> to width <code>w</code> with char <code>c</code>.</td>
<td><code>padR(MATCH, 10, ".")</code> → <code>"Val......."</code></td>
</tr>
<tr>
<td><code>vars(t)</code></td>
<td>Declares custom variables for use across replacements.</td>
<td><code>vars({sum=0})</code></td>
</tr>
<tr>
<td><code>lkp(k, p, c)</code></td>
<td>Looks up key <code>k</code> in file <code>p</code> and returns the value.</td>
<td><code>set(lkp(MATCH, "C:\\list.lkp"))</code></td>
</tr>
<tr>
<td><code>lvars(p)</code></td>
<td>Loads all key-value pairs from file <code>p</code> as global variables.</td>
<td><code>lvars("C:\\config.vars")</code></td>
</tr>
<tr>
<td><code>lcmd(p)</code></td>
<td>Loads external Lua functions from file <code>p</code> to extend functionality.</td>
<td><code>lcmd("C:\\helpers.lcmd")</code></td>
</tr>
</table>
</section>
<br>
<section id="Commands">
<h2>Command Reference</h2>
<h3>String Composition</h3>
<p><code>..</code> is employed for concatenation.<br>
E.g., <code>"Detected "..CNT.." times."</code></p>
<br>
<h3 id="setstrorcalc">set(strOrCalc)</h3>
<p>Directly outputs strings or numbers, replacing the matched text with a specified or calculated value.</p>
<table class="optionsTable">
<tr>
<th>Find</th>
<th>Replace with</th>
<th>Regex</th>
<th>Description/Expected Output</th>
</tr>
<tr>
<td><code>apple</code></td>
<td><code>set("banana")</code></td>
<td>No</td>
<td>Replaces every occurrence of <code>apple</code> with the string <code>"banana"</code>.</td>
</tr>
<tr>
<td><code>(\d+)</code></td>
<td><code>set(tonum(CAP1) * 2)</code></td>
<td>Yes</td>
<td>Doubles any found number; e.g., <code>10</code> becomes <code>20</code>.</td>
</tr>
<tr>
<td><code>found</code></td>
<td><code>set("Found #"..CNT.." at position "..APOS)</code></td>
<td>No</td>
<td>Shows how many times <code>found</code> was detected and its absolute position.</td>
</tr>
</table>
<br>
<h3 id="condcondition-trueval-falseval">cond(condition, trueVal, [falseVal])</h3>
<p>Evaluates the condition and outputs <code>trueVal</code> if the condition is true, otherwise <code>falseVal</code>. If <code>falseVal</code> is omitted, the original text remains unchanged when the condition is false.</p>
<table class="optionsTable">
<tr>
<th>Find</th>
<th>Replace with</th>
<th>Regex</th>
<th>Description/Expected Output</th>
</tr>
<tr>
<td><code>word</code></td>
<td><code>cond(CNT==1, "First 'word'", "Another 'word'")</code></td>
<td>No</td>
<td>For the first occurrence of <code>word</code> → <code>"First 'word'"</code>; for subsequent matches → <code>"Another 'word'"</code>.</td>
</tr>
<tr>
<td><code>(\d+)</code></td>
<td><code>cond(tonum(CAP1)>100, "Large", cond(tonum(CAP1)>50, "Medium", "Small"))</code></td>
<td>Yes</td>
<td>If > 100 → <code>"Large"</code>, if > 50 → <code>"Medium"</code>, otherwise → <code>"Small"</code>.</td>
</tr>
<tr>
<td><code>anymatch</code></td>
<td><code>cond(APOS<50, "Early in document", "Later in document")</code></td>
<td>No</td>
<td>If the absolute position <code>APOS</code> is under 50 → <code>"Early in document"</code>, otherwise → <code>"Later in document"</code>.</td>
</tr>
</table>
<br>
<h3 id="varsvariable1value1-variable2value2-">vars({Variable1=Value1, Variable2=Value2, ...})</h3>
<p><strong>Note:</strong> This command was previously named <code>init()</code> and has been renamed to <code>vars()</code>. For compatibility, <code>init()</code> still works.</p>
<p>Initializes custom variables for use in various commands, extending beyond standard variables like <code>CNT</code>, <code>MATCH</code>, <code>CAP1</code>. These variables can carry the status of previous find-and-replace operations to subsequent ones.</p>
<p>Custom variables persist from match to match within a single <strong>'Replace All'</strong> operation and can transfer values between list entries. Each new operation (button click) starts with a fresh state. In multi-file replacements, variables also reset at each <strong>document switch</strong>.</p>
<p><strong>Init usage:</strong> Can be used as an init entry (empty Find) to preload before replacements; not mandatory. See <a href="#preload-variables--helpers">Preload Variables & Helpers</a> for workflow and examples.</p>
<table class="optionsTable">
<tr>
<th>Find</th>
<th>Replace</th>
<th>Before</th>
<th>After</th>
<th>Regex</th>
<th>Scope CSV</th>
<th>Description</th>
</tr>
<tr>
<td><code>(\d+)</code></td>
<td><code>vars({COL2=0,COL4=0}); cond(LCNT==4, COL2+COL4);</code><br><code>if COL==2 then COL2=tonum(CAP1) end;</code><br><code>if COL==4 then COL4=tonum(CAP1) end;</code></td>
<td>1,20,text,2,0<br>2,30,text,3,0<br>3,40,text,4,0</td>
<td>1,20,text,2,22.0<br>2,30,text,3,33.0<br>3,40,text,4,44.0</td>
<td>Yes</td>
<td>Yes</td>
<td>Tracks values from columns 2 and 4, sums them, and updates the result for the 4th match in the current line.</td>
</tr>
<tr>
<td><code>\d{2}-[A-Z]{3}</code></td>
<td><code>vars({MATCH_PREV=''}); cond(LCNT==1,'Moved', MATCH_PREV); MATCH_PREV=MATCH;</code></td>
<td>12-POV,00-PLC<br>65-SUB,00-PLC<br>43-VOL,00-PLC</td>
<td>Moved,12-POV<br>Moved,65-SUB<br>Moved,43-VOL</td>
<td>Yes</td>
<td>No</td>
<td>Uses <code>MATCH_PREV</code> to track the first match in the line and shift it to the 2nd (<code>LCNT</code>) match during replacements.</td>
</tr>
</table>
<br>
<h3 id="lvarsfilepath">lvars(filePath)</h3>
<p>Loads custom variables from an external file. The file specifies variable names and their corresponding values. The loaded variables can then be used throughout the Replace process, similar to how variables defined with <a href="#varsvariable1value1-variable2value2-">vars</a> work.</p>
<p>The parameter <strong>filePath</strong> must specify a valid path to a file. Supported path formats include:</p>
<ul>
<li>Escaped Backslashes: <code>"C:\\path\\to\\file.vars"</code></li>
<li>Forward Slashes: <code>"C:/path/to/file.vars"</code></li>
<li>Long Bracket String: <code>[[C:\path\to\file.vars]]</code></li>
</ul>
<p><strong>File:</strong></p>
<pre><code>-- Local variables remain private
local PATH = [[C:\Data\Projects\]]
-- Only the returned variables are accessible in Replace operations
return {
userName = "Alice",
threshold = 10,
enableFeature = true,
fullPath = PATH .. "dataFile.lkp"
}
</code></pre>
<p><strong>Init usage:</strong> Can be used as an init entry (empty Find) to preload before replacements; not mandatory. See <a href="#preload-variables--helpers">Preload Variables & Helpers</a> for workflow and examples.</p>
<table class="optionsTable">
<tr>
<th>Find</th>
<th>Replace</th>
<th>Regex</th>
<th>Scope CSV</th>
<th>Description</th>
</tr>
<tr>
<td><em>(empty)</em></td>
<td><code>lvars([[C:\tmp\myVars.vars]])</code></td>
<td>No</td>
<td>No</td>
<td>Loads variables such as <code>userName = "Alice"</code> and <code>threshold = 10</code>.</td>
</tr>
<tr>
<td><code>Hello</code></td>
<td><code>set(userName)</code></td>
<td>No</td>
<td>No</td>
<td>Replaces <code>Hello</code> with the value of the variable <code>userName</code>, e.g., "Alice".</td>
</tr>
<tr>
<td><code>(\d+)</code></td>
<td><code>cond(threshold > 5, "Above", "Below")</code></td>
<td>Yes</td>
<td>No</td>
<td>Replaces the match based on the condition evaluated using the variable <code>threshold</code>.</td>
</tr>
</table>
<p><strong>Key Points:</strong></p>
<ul>
<li><strong>Conditional Loading:</strong> Variables can be loaded conditionally by placing <code>lvars()</code> alongside a specific Find pattern. In this case, the variables are only initialized when the pattern matches.</li>
<li><strong>Local vs. Returned Variables:</strong> Only variables explicitly included in the return table of the .vars file are available for use. Any local variables remain private to the file.</li>
</ul>
<br>
<h3 id="lkpkey-hpath-inner">lkp(key, hpath, inner)</h3>
<p>Performs an external lookup of <strong>key</strong> against an indexed data file located at <strong>hpath</strong> and returns the corresponding value. By default, if the <strong>key</strong> is not found, <code>lkp()</code> simply reverts to the key itself. Setting <strong>inner</strong> to <code>true</code> instead yields a <code>nil</code> result when the key is missing, allowing for conditional checks or deeper nested logic.</p>
<h4>Key and File Path</h4>
<ul>
<li><strong>Key:</strong> The <strong>key</strong> can be either a string or a number. Numbers are automatically converted to strings to ensure compatibility in the lookup process.</li>
<li><strong>File Path (hpath):</strong> The <strong>hpath</strong> must point to a valid <code>.lkp</code> file that returns a table of data.<br>
<strong>Supported Path Formats:</strong>
<ul>
<li>Escaped Backslashes: <code>"C:\\path\\to\\file.lkp"</code></li>
<li>Forward Slashes: <code>"C:/path/to/file.lkp"</code></li>
<li>Long Bracket String: <code>[[C:\path\to\file.lkp]]</code></li>
</ul>
</li>
</ul>
<h4>Data File Format</h4>
<p>Each lkp file must be defined as a table of entries in the form <code>{ [keys], value }</code>, where <code>[keys]</code> can be:</p>
<ul>
<li>A single key (e.g., <code>"001"</code>).</li>
<li>An array of keys (e.g., <code>{ "001", "1", 1 }</code>) mapping to the same value.</li>
</ul>
<pre><code>return {
{ {"001", "1", 1}, "One" },
{ 2, "Two" },
{ "003", "Three" }
}
</code></pre>
<p>In this example:</p>
<ul>
<li><code>'001'</code>, <code>'1'</code>, and <code>1</code> all correspond to <code>"One"</code>.</li>
<li><code>2</code> corresponds to <code>"Two"</code>.</li>
<li><code>'003'</code> directly maps to <code>"Three"</code>.</li>
</ul>
<h4>Caching Mechanism</h4>
<p>Once <code>lkp()</code> loads the data file for <strong>hpath</strong>, the parsed table is cached in memory for the duration of the Replace-All operation.</p>
<h4>inner Flag</h4>
<ul>
<li><strong><code>false</code> (default, can be omitted):</strong> If the key is not found, <code>lkp()</code> returns the <strong>search term itself</strong> (e.g., <code>MATCH</code>, <code>CAP1</code>), instead of a mapped value.</li>
<li><strong><code>true</code>:</strong> If the key is not found, <code>lkp()</code> returns <code>nil</code>, allowing conditional handling.</li>
</ul>
<h4>Examples</h4>
<table class="optionsTable">
<tr>
<th>Find</th>
<th>Replace</th>
<th>Regex</th>
<th>Scope CSV</th>
<th>Description</th>
</tr>
<tr>
<td><code>\b\w+\b</code></td>
<td><code>lkp(MATCH, [[C:\tmp\hash.lkp]], true)</code></td>
<td>Yes</td>
<td>No</td>
<td>Uses <strong>inner = true</strong>: If found, replaces with mapped value. If not found, original word is removed.</td>
</tr>
<tr>
<td><code>(\d+)</code></td>
<td><code>lkp(CAP1, "C:/path/to/myLookupFile.lkp")</code></td>
<td>Yes</td>
<td>No</td>
<td>Uses <strong>inner = false</strong> (default): If found, replaces with mapped value. If not, returns <code>CAP1</code>.</td>
</tr>
<tr>
<td><code>\b\w+\b</code></td>
<td><code>output = lkp(MATCH, [[C:\tmp\hash.lkp]], true); set(output or "NoKey")</code></td>
<td>Yes</td>
<td>No</td>
<td>Uses <strong>inner = true</strong>: If lookup result is non-<code>nil</code>, replaces with mapped value; otherwise <code>"NoKey"</code>.</td>
</tr>
<tr>
<td><code>\b\w+\b</code></td>
<td><code>cond(COL==3, lkp(MATCH, [[C:/tmp/col3_hash.lkp]]))</code></td>
<td>No</td>
<td>Yes</td>
<td>Looks up values in the third column (<code>COL==3</code>) using a separate lookup file.</td>
</tr>
</table>
<br>
<h3 id="fmtnnum-maxdecimals-fixeddecimals">fmtN(num, maxDecimals, fixedDecimals)</h3>
<p>Formats numbers based on precision (maxDecimals) and whether the number of decimals is fixed (fixedDecimals being true or false).</p>
<p><strong>Note:</strong> The <code>fmtN()</code> command can exclusively be used within the <code>set()</code> and <code>cond()</code> commands.</p>
<table class="optionsTable">
<tr>
<th>Example</th>
<th>Result</th>
</tr>
<tr>
<td><code>set(fmtN(5.73652, 2, true))</code></td>
<td>5.74</td>
</tr>
<tr>
<td><code>set(fmtN(5.0, 2, true))</code></td>
<td>5.00</td>
</tr>
<tr>
<td><code>set(fmtN(5.73652, 4, false))</code></td>
<td>5.7365</td>
</tr>
<tr>
<td><code>set(fmtN(5.0, 4, false))</code></td>
<td>5</td>
</tr>
</table>
<br>
<h3 id="lcmdpath">lcmd(path)</h3>
<p>Load user-defined helper functions from a Lua file. The file must <code>return</code> a table of functions. <code>lcmd</code> registers those functions as globals for the current run.</p>
<p><strong>Purpose:</strong> Add reusable helper functions (formatters, converters, logging, small logic). Helpers <strong>must return a string or number</strong> and are intended to be called from <strong>action</strong> commands (e.g. <code>set(...)</code>, <code>cond(...)</code>).</p>
<p><strong>Init usage:</strong> Can be used as an init entry (empty Find) to preload before replacements; not mandatory. See <a href="#preload-variables--helpers">Preload Variables & Helpers</a> for workflow and examples.</p>
<table class="optionsTable">
<tr>
<th>Find</th>
<th>Replace</th>
<th>Regex</th>
<th>Description</th>
</tr>
<tr>
<td><em>(empty)</em></td>
<td><code>lcmd([[C:\tmp\helpers.lcmd]])</code></td>
<td>No</td>
<td>Load helpers from file (init row — no replacement).</td>
</tr>
<tr>
<td><code>(.+)</code></td>
<td><code>set(slug(CAP1))</code></td>
<td>Yes</td>
<td>Create a URL-safe slug from the whole line using <code>slug</code>.</td>
</tr>
<tr>
<td><code>([a-z_]+)</code></td>
<td><code>set(titleCase(CAP1))</code></td>
<td>Yes</td>
<td>Convert snake_case to Title Case using <code>titleCase</code>.</td>
</tr>
<tr>
<td><code>\{\{(.*?)\}\}</code></td>
<td><code>set(file_log(MATCH, [[C:\tmp\out.txt]]))</code></td>
<td>Yes</td>
<td>Logs the search hit to a file, leaving original text unchanged.</td>
</tr>
</table>
<p><strong>File format:</strong></p>
<pre><code>-- C:\tmp\helpers.lcmd
return {
-- slug: create a URL-friendly slug
-- Usage: set(slug("Hello World!")) → "hello-world"
slug = function(s)
s = tostring(s or ""):lower()
s = s:gsub("%s+", "-"):gsub("[^%w%-]", "")
return s
end,
-- titleCase: convert snake_case or space-separated to Title Case
-- Usage: set(titleCase("hello_world")) → "Hello World"
titleCase = function(s)
s = tostring(s or "")
s = s:gsub("_", " ")
s = s:gsub("(%a)([%w]*)", function(first, rest)
return first:upper() .. rest:lower()
end)
return s
end,
-- wrap: wrap text at specified width
-- Usage: set(wrap("long text here", 40)) → wrapped text
wrap = function(s, width)
s = tostring(s or "")
width = tonumber(width) or 80
local result = {}
for line in s:gmatch("[^\n]+") do
while #line > width do
local pos = line:sub(1, width):match(".*()%s") or width
table.insert(result, line:sub(1, pos - 1))
line = line:sub(pos + 1)
end
table.insert(result, line)
end
return table.concat(result, "\n")
end,
-- file_log: append match to file, return original match
-- Usage: set(file_log(MATCH, [[C:\tmp\out.txt]]))
file_log = function(match, path)
if match == nil then return "" end
path = path or [[C:\tmp\matches.txt]]
local f = io.open(path, "a")
if not f then return match end
f:write(tostring(match) .. "\n")
f:close()
return match
end,
}
</code></pre>
</section>
<br>
<section id="StringHelpers">
<h2>String Formatting Helpers</h2>
<p>The following built-in helper functions are available for string manipulation. These are ready to use without loading external files.</p>
<table class="optionsTable">
<tr>
<th>Function</th>
<th>Description</th>
<th>Example</th>
</tr>
<tr>
<td><code>trim(s)</code></td>
<td>Removes leading and trailing whitespace from string <code>s</code>. Useful for cleaning up database dumps or messy CSVs.</td>
<td><code>trim(" abc ")</code> → <code>"abc"</code></td>
</tr>
<tr>
<td><code>tonum(s)</code></td>
<td>Converts string <code>s</code> to number. Accepts both dot (.) and comma (,) as decimal separator. Returns <code>nil</code> if conversion fails.</td>
<td><code>tonum("3,14")</code> → <code>3.14</code></td>
</tr>
<tr>
<td><code>padL(s, w, c)</code></td>
<td>Pads string <code>s</code> on the <strong>left</strong> to width <code>w</code> with character <code>c</code> (default: space). Ideal for zero-padding IDs or generating sorted file names like <code>file_001.txt</code>.</td>
<td><code>padL("42", 5, "0")</code> → <code>"00042"</code></td>
</tr>
<tr>
<td><code>padR(s, w, c)</code></td>
<td>Pads string <code>s</code> on the <strong>right</strong> to width <code>w</code> with character <code>c</code> (default: space). Useful to align text into fixed-width columns.</td>
<td><code>padR("Val", 10, ".")</code> → <code>"Val......."</code></td>
</tr>
</table>
<h4>Usage Examples</h4>
<table class="optionsTable">
<tr>
<th>Find</th>
<th>Replace</th>
<th>Regex</th>
<th>Description</th>
</tr>
<tr>
<td><code>(\d+)</code></td>
<td><code>set(padL(CAP1, 6, "0"))</code></td>
<td>Yes</td>
<td>Zero-pad numbers to 6 digits: <code>42</code> → <code>000042</code></td>
</tr>
<tr>
<td><code>(\w+)</code></td>
<td><code>set(padR(CAP1, 15, " "))</code></td>
<td>Yes</td>
<td>Right-pad words to 15 chars for column alignment.</td>
</tr>
<tr>
<td><code>^\s*(.+?)\s*$</code></td>
<td><code>set(trim(CAP1))</code></td>
<td>Yes</td>
<td>Remove leading/trailing whitespace from each line.</td>
</tr>
<tr>
<td><code>ID_(\d+)</code></td>
<td><code>set("ID_" .. padL(CAP1, 4, "0"))</code></td>
<td>Yes</td>
<td>Normalize IDs: <code>ID_7</code> → <code>ID_0007</code></td>
</tr>
</table>
</section>
<br>
<section id="preload-variables--helpers">
<h2>Preload Variables & Helpers</h2>
<p>Use init entries (empty Find) to preload variables or helper functions before any replacements run. Init entries run once per Replace-All (or per list pass) and do not change text directly.</p>
<h3>How it works</h3>
<ul>
<li><strong>Place <code>vars()</code>, <code>lvars()</code> or <code>lcmd()</code> next to an empty Find field.</strong></li>
<li>This entry does <strong>not</strong> search for matches but runs before replacements begin.</li>
<li>It ensures that <strong>variables and helpers are loaded once</strong>, regardless of their position in the list.</li>
<li>Use <strong>Use Variables = ON</strong> for init rows so loaded variables/helpers are available to later rows.</li>
</ul>
<h3>Examples</h3>
<table class="optionsTable">