Due to issues with the Internet.ee domain registry, our main domain, paste.ee, is currently disabled due to abuse reports. We are looking into alternative domains to continue operation, but for now the pastee.dev domain is the primary domain.
If you wish to blame someone, blame the scum using this site as a malware host.
Description: regex
Submitted on January 5, 2016 at 08:03 PM

Section 1 (D)

import std.stdio : writeln, writefln;
import std.range : take, array, join;
import std.algorithm : map, filter, splitter;
import std.regex;
import std.datetime;

auto stopTime(alias F)() {
	auto sw = StopWatch(AutoStart.yes);
	// writeln(F("big.txt"));
	writeln(F("big.txt").length);
	sw.stop();
	return sw.peek.msecs;
}

auto search(string pattern)(string file) {
	auto r = ctRegex!(pattern);
  import std.mmfile : MmFile;
  import std.file : getSize;
  auto sz = getSize(file);
  auto mmf = new MmFile(file, MmFile.Mode.read, sz, null);
  //mmfile bug??
  import core.memory : GC;
  GC.addRoot(mmf[].ptr);
  scope(exit){
    GC.removeRoot(mmf[].ptr);
  }
  static auto matchLine(T)(T reg){
    return reg["name"]
      .splitter!(a => a == ' ' || a == ';' || a == '\"')
      .filter!(a => a != """")
      .join(".");
  }
  import std.string : lineSplitter;
  return (cast(string)mmf[])
    .lineSplitter()
    .take(10_000_000)
    .map!(a => a.matchFirst(r))
    .filter!(a => !a.empty)
    .map!(matchLine)
    .array;
}

int main(string[] argv) {
	auto elapsed = stopTime!(search!(r"\{.*(?P<name>Microsoft.*)\|\]"));
	writefln("Elapsed: %s", elapsed);
  return 0;
}