Can Dopus search in file contents provide a list of contents searched?

This script will loop through all selected files and create text files containing regex matching lines next to them. The regex might need some finetuning, but that's the fun part, right?

// https://resource.dopus.com/t/can-dopus-search-in-file-contents-provide-a-list-of-contents-searched/39904

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;
    var fso = new ActiveXObject('Scripting.FileSystemObject');

    cmd.deselect = false;

    cmd.RunCommand('Set UTILITY=otherlog');
    DOpus.ClearOutput();
    
    var regEx = /[^\t\n\r]+\t[0-9]{2}-[0-9]{5}\N+/gi;

    DOpus.Output('Enumerating...\n');

    for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {
        var item = e.item();
        DOpus.Output('File: ' + item);

        var inFile = fso.OpenTextFile(item, 1);
        var outFile = fso.CreateTextFile(item + '-badges.txt');
        var total = 0;

        while (!inFile.AtEndOfStream) {
            var line = inFile.ReadLine();
            var arrBadges = line.match(regEx) || [];
            var badgeCount = arrBadges.length;
            if (badgeCount == 0) continue;
            total += badgeCount;
            outFile.WriteLine(line);
        }

        inFile.close();
        outFile.close();

        DOpus.Output('  Badges found: ' + total + '\n');
    }
    DOpus.Output('\n... done.');
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>39904</label>
	<icon1>#newcommand</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>// https://resource.dopus.com/t/can-dopus-search-in-file-contents-provide-a-list-of-contents-searched/39904</instruction>
		<instruction />
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var tab = clickData.func.sourcetab;</instruction>
		<instruction>    var fso = new ActiveXObject(&apos;Scripting.FileSystemObject&apos;);</instruction>
		<instruction />
		<instruction>    cmd.deselect = false;</instruction>
		<instruction />
		<instruction>    cmd.RunCommand(&apos;Set UTILITY=otherlog&apos;);</instruction>
		<instruction>    DOpus.ClearOutput();</instruction>
		<instruction>    </instruction>
		<instruction>    var regEx = /[^\t\n\r]+\t[0-9]{2}-[0-9]{5}\N+/gi;</instruction>
		<instruction />
		<instruction>    DOpus.Output(&apos;Enumerating...\n&apos;);</instruction>
		<instruction />
		<instruction>    for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {</instruction>
		<instruction>        var item = e.item();</instruction>
		<instruction>        DOpus.Output(&apos;File: &apos; + item);</instruction>
		<instruction />
		<instruction>        var inFile = fso.OpenTextFile(item, 1);</instruction>
		<instruction>        var outFile = fso.CreateTextFile(item + &apos;-badges.txt&apos;);</instruction>
		<instruction>        var total = 0;</instruction>
		<instruction />
		<instruction>        while (!inFile.AtEndOfStream) {</instruction>
		<instruction>            var line = inFile.ReadLine();</instruction>
		<instruction>            var arrBadges = line.match(regEx) || [];</instruction>
		<instruction>            var badgeCount = arrBadges.length;</instruction>
		<instruction>            if (badgeCount == 0) continue;</instruction>
		<instruction>            total += badgeCount;</instruction>
		<instruction>            outFile.WriteLine(line);</instruction>
		<instruction>        }</instruction>
		<instruction />
		<instruction>        inFile.close();</instruction>
		<instruction>        outFile.close();</instruction>
		<instruction />
		<instruction>        DOpus.Output(&apos;  Badges found: &apos; + total + &apos;\n&apos;);</instruction>
		<instruction>    }</instruction>
		<instruction>    DOpus.Output(&apos;\n... done.&apos;);</instruction>
		<instruction>}</instruction>
	</function>
</button>

How to use buttons and scripts from this forum