-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhelp_use_variables_light.html
886 lines (804 loc) · 38.4 KB
/
help_use_variables_light.html
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
<!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.2rem; text-align: left; font-weight: bold; font-style: normal; padding: 0; margin: 0;}
h3 {font-size: 1rem; 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 = false; // 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="#FirstSteps">First Steps</a>
<a href="#Variables">Variables</a>
<a href="#Commands">Commands</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="#Operators">Operators</a>
<a href="#IfThenLogic">If-Then Logic</a>
<a href="#DebugOption">Debug Option</a>
<a href="#FurtherFunctions">Math & String Functions</a>
<a href="#Examples">Examples</a>
</nav>
<article>
<section id="Introduction">
<h2>Introduction</h2>
<p>
Activate the <strong>Use Variables</strong> checkbox to employ variables associated with specified strings, allowing for conditional and computational operations within the replacement string. This Dynamic Substitution is compatible with all search settings of Search Mode, Scope, and the other options. The functionality relies on the
<a href="https://www.lua.org/" target="_blank">Lua engine</a>.
</p>
</section>
<section id="FirstSteps">
<h2>First Steps</h2>
<p>
Utilize either the <a href="#setstrorcalc"><code>set()</code></a> or <a href="#condcondition-trueval-falseval"><code>cond()</code></a> command in 'Replace with:' to channel the output as the replacement string. Only one of these commands should be used at a time.
</p>
</section>
<section id="Variables">
<h2>Variables</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>LINE</strong></td>
<td>Line number where the string is found.</td>
</tr>
<tr>
<td><strong>APOS</strong></td>
<td>Absolute character position in the document.</td>
</tr>
<tr>
<td><strong>LPOS</strong></td>
<td>Relative line position.</td>
</tr>
<tr>
<td><strong>LCNT</strong></td>
<td>Count of the detected string within the line.</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>CAP1</strong>, <strong>CAP2</strong>,...</td>
<td>These variables are equivalents to regex capture groups, designed for use in the 'Use Variables' environment. They are specifically suited for calculations and conditional operations within this environment. Although their counterparts ($1, $2, ...) cannot be used here.</td>
</tr>
<tr>
<td colspan="2">
<strong>Decimal Separator:</strong> When <code>MATCH</code> and <code>CAP</code> variables are used to read numerical values for further calculations, both dot (.) and comma (,) can serve as decimal separators. However, these variables do not support the use of thousands separators.
</td>
</tr>
</table>
</section>
<section id="Commands">
<h2>Commands</h2>
<h3 id="setstrorcalc">set(strOrCalc)</h3>
<p>Outputs strings or numbers directly.</p>
<table class="optionsTable">
<tr>
<th>Example</th>
<th>Result (assuming LINE = 5, CNT = 3)</th>
</tr>
<tr>
<td><code>set("replaceString"..CNT)</code></td>
<td>"replaceString3"</td>
</tr>
<tr>
<td><code>set(LINE+5)</code></td>
<td>"10"</td>
</tr>
</table>
<h3 id="condcondition-trueval-falseval">cond(condition, trueVal, [falseVal])</h3>
<p>Implements if-then-else logic, or if-then if <em>falseVal</em> is omitted.</p>
<table class="optionsTable">
<tr>
<th>Example</th>
<th>Result (assuming LINE = 5)</th>
</tr>
<tr>
<td><code>cond(LINE<=5 or LINE>=9, "edge", "center")</code></td>
<td>"edge"</td>
</tr>
<tr>
<td><code>cond(LINE<3, "Modify this line")</code></td>
<td>(Original text remains unchanged)</td>
</tr>
<tr>
<td>
<code>cond(LINE<10,
cond(LINE<5,
cond(LINE>2, "3-4", "0-2"),
"5-9"),
"10+")</code>
</td>
<td>"5-9" (Nested condition)</td>
</tr>
</table>
<!-- vars({Variable1=Value1, Variable2=Value2, ...}) -->
<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 maintain their values throughout a single Replace-All or within a list of multiple Replace operations, allowing them to transfer values from one list entry to the next. They reset at the start of each new document in <em>'Replace All in All Open Documents'</em>.
</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);<br>
if COL==2 then COL2=CAP1 end;<br>
if COL==4 then COL4=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 MATCH_PREV to track the value of the first match in the line and shift it to the 2nd (LCNT) match.</td>
</tr>
</table>
<p>
An empty Find string (<code>*(empty)*</code>) can be used to set variables for the entire Find and Replace list without tying it to a specific Find action. This entry does not match any text but is executed once at the beginning of the 'Replace' or 'Replace All' process when "Use List" is enabled, allowing the Replace field to run initialization commands like <code>vars()</code> for the entire operation. The position of this entry in the list does not affect its behavior.
</p>
<table class="optionsTable">
<tr>
<th>Find</th>
<th>Replace</th>
<th>Description/Expected Output</th>
</tr>
<tr>
<td>*(empty)*</td>
<td>
<code>vars({<br>
VpersonName = FNAME:sub(1, (FNAME:find(" - ", 1, true) or 0) - 1),<br>
Vdepartment = FNAME:sub((FNAME:find(" - ", 1, true) or #FNAME + 1) + 3, (FNAME:find(".", 1, true) or 0) - 1)
})</code>
</td>
<td>Extracts <code>VpersonName</code> and <code>Vdepartment</code> from the filename of the active document in the format <code><Name> - <Department>.xml</code> using the <code>vars</code> action. Triggered only once at the start of the replace process when <code>Find</code> is empty.</td>
</tr>
<tr>
<td><code>personname</code></td>
<td><code>set(VpersonName)</code></td>
<td>Replaces <code>personname</code> with the content of the variable <code>VpersonName</code>, previously initialized by the <code>vars</code> action.</td>
</tr>
<tr>
<td><code>department</code></td>
<td><code>set(Vdepartment)</code></td>
<td>Replaces <code>department</code> with the content of the variable <code>Vdepartment</code>, previously initialized by the <code>vars</code> action.</td>
</tr>
</table>
<!-- lvars(filePath) -->
<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-"><code>vars</code></a> work.
</p>
<p>The parameter <strong>filePath</strong> must specify a valid path to a file. Supported path formats include:</p>
<ul>
<li>Long Bracket String: <code>[[C:\path\to\file.vars]]</code></li>
<li>Forward Slashes: <code>"C:/path/to/file.vars"</code></li>
<li>Escaped Backslashes: <code>"C:\\path\\to\\file.vars"</code></li>
</ul>
<p><strong>Example File:</strong></p>
<pre><code>return {
userName = "Alice",
threshold = 10,
enableFeature = true
}
</code></pre>
<table class="optionsTable">
<tr>
<th>Find</th>
<th>Replace</th>
<th>Regex</th>
<th>Scope CSV</th>
<th>Description</th>
</tr>
<tr>
<td>*(empty)*</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> from <code>myVars.vars</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>
An empty Find string (<code>*(empty)*</code>) initializes variables globally at the start of the 'Replace' or 'Replace All' process when "Use List" is enabled. This initialization runs only once and is independent of specific matches or its position in the list. Alternatively, variables can be loaded conditionally by combining <code>lvars</code> or <code>vars</code> with a Find string, triggering the variable assignment only when the specified string is matched.
</p>
<!-- lkp(key, hpath, inner) -->
<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> 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 key can be either a string or a number. Numbers are automatically converted to strings for compatibility.</li>
<li><strong>File Path (hpath)</strong>: The hpath must point to a valid <code>.lkp</code> file that returns a table of data.
<br><em>Supported Path Formats</em>:
<ul>
<li>Long Bracket String: <code>[[C:\path\to\file.lkp]]</code></li>
<li>Forward Slashes: <code>"C:/path/to/file.lkp"</code></li>
<li>Escaped Backslashes: <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:
<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>
</p>
<h4>Caching Mechanism</h4>
<p>
Once <code>lkp()</code> loads the data file for <em>hpath</em>, the parsed table is cached in memory for the duration of the Replace-All operation.
</p>
<h4>inner Flag</h4>
<ul>
<li><strong>false</strong> ((default, can be omitted)): If the key is not found, <code>lkp()</code> returns the original key.</li>
<li><strong>true</strong>: If the key is not found, <code>lkp()</code> yields a <code>nil</code> result, which can be used with <code>cond()</code> for 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 a match is found in the lookup file, replaces it with the mapped value. If no match is found, the 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 a match is found, replaces it with the mapped value. Otherwise, returns the original text (<code>CAP1</code>).</td>
</tr>
<tr>
<td><code>\b\w+\b</code></td>
<td><code>cond(lkp(MATCH, [[C:\tmp\hash.lkp]], true).result ~= nil, lkp(MATCH, [[C:\tmp\hash.lkp]], true).result, "NoKey")</code></td>
<td>Yes</td>
<td>No</td>
<td>Uses <strong>inner = true</strong>: If the lookup result is non-<code>nil</code>, replaces with the mapped value. Otherwise, replaces with <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 (<code>col3_hash.lkp</code>) if a match is found.</td>
</tr>
</table>
<h3 id="fmtnnum-maxdecimals-fixeddecimals">fmtN(num, maxDecimals, fixedDecimals)</h3>
<p>
Formats numbers based on precision (<em>maxDecimals</em>) and whether the number of decimals is fixed (<em>fixedDecimals</em> being <code>true</code> or <code>false</code>).
</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>
</section>
<section id="Operators">
<h2>Operators</h2>
<table class="optionsTable">
<tr>
<th>Type</th>
<th>Operators</th>
<th>Example</th>
</tr>
<tr>
<td>Concatenation</td>
<td><code>..</code></td>
<td><code>set("Found "..CNT)</code></td>
</tr>
<tr>
<td>Arithmetic</td>
<td><code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>, <code>^</code>, <code>%</code></td>
<td><code>set(CNT * 2)</code></td>
</tr>
<tr>
<td>Relational</td>
<td><code>==</code>, <code>~=</code>, <code><</code>, <code>></code>, <code><=</code>, <code>>=</code></td>
<td><code>cond(LINE == 1, "First", "Not first")</code></td>
</tr>
<tr>
<td>Logical</td>
<td><code>and</code>, <code>or</code>, <code>not</code></td>
<td><code>cond(LINE > 5 and CNT < 10, "Midrange", "Other")</code></td>
</tr>
</table>
</section>
<section id="IfThenLogic">
<h2>If-Then Logic</h2>
<p>
If-then logic is integral for dynamic replacements, allowing users to set custom variables based on specific conditions. This enhances the versatility of find-and-replace operations.
</p>
<p>
<strong>Note</strong>: Do not embed <code>cond()</code>, <code>set()</code>, or <code>vars()</code> within <code>if</code> statements; <code>if</code> statements are exclusively for adjusting custom variables.
</p>
<h3>Syntax Combinations</h3>
<ul>
<li><code>if condition then ... end</code></li>
<li><code>if condition then ... else ... end</code></li>
<li><code>if condition then ... elseif another_condition then ... end</code></li>
<li><code>if condition then ... elseif another_condition then ... else ... end</code></li>
</ul>
<h3>Example</h3>
<p>
This example shows how to use <code>if</code> statements with <code>cond()</code> to manage variables based on conditions:
</p>
<code>vars({MVAR=""}); if CAP2~=nil then MVAR=MVAR..CAP2 end; cond(string.sub(CAP1,1,1)~="#", MVAR); if CAP2~=nil then MVAR=string.sub(CAP1,4,-1) end</code>
</section>
<section id="DebugOption">
<h2>DEBUG option</h2>
<p>
The <code>DEBUG</code> option lets you inspect global variables during replacements. When enabled, it opens a message box displaying the current values of all global variables for each replacement hit, requiring confirmation to proceed to the next match. Initialize the <code>DEBUG</code> option in your replacement string to enable it.
</p>
<h3>Example</h3>
<table class="optionsTable">
<tr>
<th>Find:</th>
<th>Replace with:</th>
</tr>
<tr>
<td><code>(\d+)</code></td>
<td><code>vars({DEBUG=true}); set("Number: "..CAP1)</code></td>
</tr>
</table>
</section>
<section id="FurtherFunctions">
<h2>Math & String Functions</h2>
<p>
MultiReplace uses the <a href="https://www.lua.org/" target="_blank">Lua engine</a>, allowing for Lua math operations and string methods. Refer to
<a href="https://www.lua.org/manual/5.4/manual.html#6.4" target="_blank">Lua String Manipulation</a> and
<a href="https://www.lua.org/manual/5.4/manual.html#6.6" target="_blank">Lua Mathematical Functions</a> for more information.
</p>
</section>
<section id="Examples">
<h2>Examples</h2>
<table class="optionsTable">
<tr>
<th>Find in:</th>
<th>Replace with:</th>
<th>Description/Expected Output</th>
<th>Regex</th>
<th>Scope CSV</th>
</tr>
<tr>
<td><code>;</code></td>
<td><code>cond(LCNT==5,";Column5;")</code></td>
<td>Adds a 5th Column for each line into a `;` delimited file.</td>
<td>No</td>
<td>No</td>
</tr>
<tr>
<td><code>key</code></td>
<td><code>set("key"..CNT)</code></td>
<td>Enumerates key values by appending the count of detected strings. E.g., key1, key2, key3, etc.</td>
<td>No</td>
<td>No</td>
</tr>
<tr>
<td><code>(\d+)</code></td>
<td><code>set(CAP1.."€ The VAT is: ".. (CAP1 * 0.15).."€ Total with VAT: ".. (CAP1 + (CAP1 * 0.15)).."€")</code></td>
<td>Finds a number and calculates the VAT at 15%, then displays the original amount, the VAT, and the total amount. E.g., `50` becomes `50€ The VAT is: 7.5€ Total with VAT: 57.5€`</td>
<td>Yes</td>
<td>No</td>
</tr>
<tr>
<td><code>---</code></td>
<td>
<code>cond(COL==1 and LINE<3, "0-2",
cond(COL==2 and LINE>2 and LINE<5, "3-4",
cond(COL==3 and LINE>=5 and LINE<10, "5-9",
cond(COL==4 and LINE>=10, "10+"))))</code>
</td>
<td>Replaces `---` with a specific range based on the `COL` and `LINE` values. E.g., `3-4` in column 2 of lines 3-4, and `5-9` in column 3 of lines 5-9.</td>
<td>No</td>
<td>Yes</td>
</tr>
<tr>
<td><code>(\d+)\.(\d+)\.(\d+)</code></td>
<td><code>cond(CAP1 > 0 and CAP2 == 0 and CAP3 == 0, MATCH, cond(CAP2 > 0 and CAP3 == 0, " " .. MATCH, " " .. MATCH))</code></td>
<td>Alters the spacing based on the hierarchy of the version numbers, aligning lower hierarchies with spaces as needed. E.g., `1.0.0` remains `1.0.0`, `1.2.0` becomes ` 1.2.0`, indicating a second-level version change.</td>
<td>Yes</td>
<td>No</td>
</tr>
<tr>
<td><code>(\d+)</code></td>
<td><code>set(CAP1 * 2)</code></td>
<td>Doubles the matched number. E.g., `100` becomes `200`.</td>
<td>Yes</td>
<td>No</td>
</tr>
<tr>
<td><code>;</code></td>
<td><code>cond(LCNT == 1, string.rep(" ", 20 - (LPOS))..";")</code></td>
<td>Inserts spaces before the semicolon to align it to the 20th character position if it's the first occurrence.</td>
<td>No</td>
<td>No</td>
</tr>
<tr>
<td><code>-</code></td>
<td><code>cond(LINE == math.floor(10.5 + 6.25 * math.sin((2 * math.pi * LPOS) / 50)), "*", " ")</code></td>
<td>Draws a sine wave across a canvas of '-' characters spanning at least 20 lines and 80 characters per line.</td>
<td>No</td>
<td>No</td>
</tr>
<tr>
<td><code>^(.*)$</code></td>
<td><code>vars({MATCH_PREV=1}); cond(MATCH == MATCH_PREV, ''); MATCH_PREV=MATCH;</code></td>
<td>Removes duplicate lines, keeping the first occurrence of each line by comparing consecutive lines.</td>
<td>Yes</td>
<td>No</td>
</tr>
</table>
</section>
</article>
</main>
<footer id="footer">
<div id="foottext" class="linklist">
<a href="https://notepad-plus-plus.org/">Notepad++</a> •
<a href="https://github.com/daddel80/notepadpp-multireplace">MultiReplace on GitHub</a>
</div>
<button type="button" id="fontdown" onclick="setFontDown();">Txt-</button>
<button type="button" id="fontup" onclick="setFontUp();">Txt+</button>
</footer>
</body>
</html>