Note: This website is archived. For up-to-date information about D projects and development, please visit

Welcome to scregexp

scregexp -Statically compiled /Compile-time Perl-compatible regular expressions


It runs faster than phobos regexps library as the expressions are compiled into a d code at compile time. The regular expression syntax is richer than phobos regexps library. There is a support for ?: ,+? and *? and others. It has an disadvantage too. The regular expressions have to be known at compile time. (They cannot be contructed at run-time) There are some exceptions, literal strings can be specified during run-time which can be part of a regular expression.
The syntax is compatible with Perl and PCRE. It can be compiled with both Phobos and Tango.


The regular expressions are parsed at compile time.

These are supported: (),(?:),(?>),(?=),(?<groupname>),\k<groupname>,\s,\w,\d,\S,\W,\D,\A,\z [^\w\s\d\S\W\D], ^, $,|,@.

These quantifiers exist : ?,??,?+,*,*?,*+,+,+?,++,{m,n},{m,n}?,{m,n}+.

These options can be used: ismx

The format of regular expressions can be: "/regex/options", "regex/options", "/regex/" ,"regex"


It uses compile-time generated functions. If the regular expression is large enough , this may cause a faulty linker to fail. There has been problems with dmd because of that. No problems with ldc. In a case, where the size of regular expression was about 1000 bytes and contained 24 options , the linker crashed or if it compiled it, the generated executable crashed when it was run.
This limitation can be circumvented if one uses getclasscode and printclass code function which give back a code which can be pasted into any code. The problem does not seem to be present in D2. (2.057)

Short example

import scregexp;
foreach(e;indexgroups!("(\w+) (\w+) (\w+)")("black white blue")) {
    if (e.start <= e.end)
      writef("group ", i," ", input[e.start..e.end]);
      writef("group ", i," ","not matched [", e.start," ", e.end, "]");

Another example

auto reg1=new screg!("/ab/"); // regular expression to use 
while (reg1.match("abxabxab"))

auto reg3=new screg!("/(?<day>monday)|(?<day>tuesday)|(?<day>wednesday)/");
if (reg3.match("wednesday"))
   // gives back the group number
   writefln(reg3._(; //prints the matched day
   writefln(reg3.getday());//prints the matched day in another way


See inside scregexp.d

How to use it in D1

Download scregexp.d ( into the directory where your sources reside.
Use import scregexp;

How to use it in D2

Download scregexpd2.d ( into the directory where your sources reside.
Use import scregexpd2;

Project Information

Status4 - Beta
Short Descriptionstatically compiled regular expression library
Home Page