The Computer Language
Benchmarks Game

regex-redux TypeScript #2 program

source code

/* The Computer Language Benchmarks Game
   http://benchmarksgame.alioth.debian.org/

   regex-dna program contributed by Josh Goldfoot
   converted from regex-dna program
   fixed by Josh Goldfoot
*/

/// <reference path="./Include/node/index.d.ts" />

var fs = require("fs");

var i = fs.readFileSync("/dev/stdin", "ascii");
var ilen = i.length;
i = i.replace(/^>.*\n|\n/mg, "");
var clen = i.length;

var q: RegExp[] = [/agggtaaa|tttaccct/ig, /[cgt]gggtaaa|tttaccc[acg]/ig,
    /a[act]ggtaaa|tttacc[agt]t/ig, /ag[act]gtaaa|tttac[agt]ct/ig,
    /agg[act]taaa|ttta[agt]cct/ig, /aggg[acg]aaa|ttt[cgt]ccct/ig,
    /agggt[cgt]aa|tt[acg]accct/ig, /agggta[cgt]a|t[acg]taccct/ig,
    /agggtaa[cgt]|[acg]ttaccct/ig];

q.forEach(qj => {
    var m: RegExpMatchArray = i.match(qj);
    console.log(qj.source, m ? m.length : 0);
});

var iub: string[] = ["-", "|", "<2>", "<3>", "<4>"];
var iubR: RegExp[] = [/\|[^|][^|]*\|/g, /<[^>]*>/g, /a[NSt]|BY/g, 
    /aND|caN|Ha[DS]|WaS/g, /tHa[Nt]/g ];

while (iub.length)
    i = i.replace(iubR.pop(), iub.pop())

console.log();
console.log(ilen);
console.log(clen);
console.log(i.length);
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
Version 2.2.9
node.js v7.9.0


Sat, 15 Apr 2017 02:27:32 GMT

MAKE:
mv regexredux.typescript-2.typescript regexredux.typescript-2.ts
/usr/local/src/node-v7.9.0-linux-x64/bin/tsc --alwaysStrict -t ESNEXT --lib es7 regexredux.typescript-2.ts
1.57s to complete and log all make actions

COMMAND LINE:
/usr/local/src/node-v7.9.0-linux-x64/bin/node --use_strict regexredux.typescript-2.js 0 < regexredux-input5000000.txt

PROGRAM OUTPUT:
agggtaaa|tttaccct 356
[cgt]gggtaaa|tttaccc[acg] 1250
a[act]ggtaaa|tttacc[agt]t 4252
ag[act]gtaaa|tttac[agt]ct 2894
agg[act]taaa|ttta[agt]cct 5435
aggg[acg]aaa|ttt[cgt]ccct 1537
agggt[cgt]aa|tt[acg]accct 1431
agggta[cgt]a|t[acg]taccct 1608
agggtaa[cgt]|[acg]ttaccct 2178

50833411
50000000
27388361