Click here to Skip to main content
11,933,037 members (61,124 online)
Click here to Skip to main content
Add your own
alternative version


66 bookmarked

DEELX - Regular Expression Engine for C++

, 25 Dec 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
DEELX regular expression engine is the most convenient and easiest engine to use.

Downloads for C++

Download Unit for Delphi (statically linked into Delphi project)

Download ActiveX for VB

Download Dynamic Link Version


DEELX is a simple regular expression engine coded in pure C++.

All source code of DEELX is just only one single header file (deelx.h). Without any other CPP or lib, you need not create a project alone for DEELX when you want to use it, and also you need not worry about link problems.

DEELX has a good compatibility that it can be compiled by Visual C++ 6.0, 7.1, 8.0 (Windows), gcc(Cygwin), gcc(Linux), gcc(FreeBSD), Turbo C++ 3.0(DOS), C++ Builder(Windows), etc. DEELX is coded using template, so char, wchar_t and other simple types can be used as its base type.

DEELX regular expression engine is the most convenient and easiest engine to use.


DEELX supports PERL compatible regular expression syntax. Besides the basic pattern syntax, DEELX has implemented many extended syntaxes:

  • Right to left match mode
  • Named capture group
  • Remark
  • Zero-width assertion
  • Independent expression
  • Conditional expression
  • Recursive expression
  • Replace operation


The most important idea of DEELX is the concept of "Element of Regular Expression". In the source code, I call it "ELX".

I regard every kind of element as "Abstract Element" => "ElxInterface". This ElxInterface has two methods: Match() and MatchNext(). Match() means to try to match the first time. If Match() returns true, but what matched is not what you want, call MatchNext() means to discard the result and try to get another successful match. If the result is still not what you want, go on calling MatchNext() till it returns false or you get what you want.

For example, two elements: (.*)(a)

  1. To call the "Match()" method of the first element(.*) will let it match all the text. But now the second element(a) will fail to match, so the match result of the previous "Match()" is not what I want.
  2. The next step is to call the "MatchNext()" method of the first element(.*). This step is also called "backtrack". The first element(.*) will reduce its repeat times, then the second element(a) will again try to match.
  3. So on, one possible final result is that: even the first element(.*) reduced to zero times, the second element still failed to match, so the overall regular expression failed to match.
  4. Another final result is that: when the first element(.*) reduced to a certain times, the second element succeeded to match, so the overall regular expression succeeded.

Match operations of all kinds of elements can be abstracted into "Match()" and "MatchNext()" operations.

That is DEELX's idea.

Demo in C++

#include "deelx.h"

int main(int argc, char * argv[])
    // text
    char * text = "12.5, a1.1, 0.123, 178";

    // declare
    static CRegexpT <char> regexp("\\b\\d+\\.\\d+", IGNORECASE | MULTILINE);

    // loop
    MatchResult result = regexp.Match(text);

    while( result.IsMatched() )
        printf("%.*s\n", result.GetEnd() - result.GetStart(), text + result.GetStart());

        // get next
        result = regexp.Match(text, result.GetEnd());

    return 0;

Regex flag definition:

 NO_FLAG        = 0,
 SINGLELINE     = 0x01,
 MULTILINE      = 0x02,
 GLOBAL         = 0x04,
 IGNORECASE     = 0x08,
 RIGHTTOLEFT    = 0x10,
 EXTENDED       = 0x20,

Wrap for Delphi (Statically Linked into Delphi Project)

Use Borland C++ Builder to compile DEELX into a .obj file, then link this .obj file into a Delphi Unit: DEELX.dcu.



  result := TMatchResult.Create();
  re := TRegexpA.Create(Edit1.Text, IGNORECASE + MULTILINE); // the 2nd is 'FLAG's

  re.Match(Edit2.Text, result);

  if result.IsMatched() then
    Edit2.SelStart := result.GetStart();
    Edit2.SelLength := result.GetEnd() - result.GetStart();
    Edit2.SelLength := 0;


Regex flags definition:

  NO_FLAG        = $00;
  SINGLELINE     = $01;
  MULTILINE      = $02;
  GLOBAL         = $04;
  IGNORECASE     = $08;
  RIGHTTOLEFT    = $10;
  EXTENDED       = $20;

Wrap to ActiveX for VB

Wrap DEELX to an ActiveX plugin, so DEELX can be used in VB or ASP file.

Private pos As Integer
Private re As New RegExLab.RegExp

Private Sub Command1_Click()
    re.Compile (Text1.Text, "igm") ' the 2nd parameter is 'FLAG's

    re.Match Text2.Text, pos

    If re.IsMatched Then
        pos = re.End
        Text2.SelStart = re.Begin
        Text2.SelLength = re.End - re.Begin
        pos = -1
        Text2.SelLength = 0
    End If
End Sub

The flags are the same as JScript.Regexp:

g  -  GLOBAL

DLL Version of DEELX

The DLL version of deelx uses stdcall format for every function, because Visual Basic can call stdcall only.

The contains two projects: one is in Visual Basic, the other is in Delphi.

References and Acknowledgements

Homepage - I'm the author, this is the homepage of DEELX.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

sswater shi
Software Developer (Senior)
China China
Begin coding from basic, since 1994. Interested in coding and database and website constructing.
My website: - Regular Expression Laboratory
The easiest regex engine:

You may also be interested in...

Comments and Discussions

GeneralRe: How can I free memory after processing regular match/replace? Pin
James 03x8-Oct-09 0:33
memberJames 03x8-Oct-09 0:33 
NewsBug found Pin
ISL08s3-Oct-09 2:28
memberISL08s3-Oct-09 2:28 
GeneralRe: Bug found Pin
ISL08s3-Oct-09 2:46
memberISL08s3-Oct-09 2:46 
GeneralRe: Bug found Pin
sswater shi3-Oct-09 6:16
membersswater shi3-Oct-09 6:16 
GeneralRe: Bug found Pin
ISL08s4-Oct-09 11:53
memberISL08s4-Oct-09 11:53 
GeneralRe: Bug found Pin
ISL08s4-Oct-09 12:03
memberISL08s4-Oct-09 12:03 
GeneralTrouble Building DLL version with Dev-C++ Pin
triple_eks27-Aug-09 14:00
membertriple_eks27-Aug-09 14:00 
GeneralRe: Trouble Building DLL version with Dev-C++ Pin
sswater shi3-Sep-09 5:56
membersswater shi3-Sep-09 5:56 
Dear, because of network problem, it's so long before I reply you. You can try to change all the "unsigned short" to "wchar_t" by your self, both in libdeelx.cpp and deelx.h. Any more problems, write to me again.
QuestionCapture Buffers Pin
Klaus Fiedler10-May-09 18:29
memberKlaus Fiedler10-May-09 18:29 
AnswerRe: Capture Buffers Pin
sswater shi11-May-09 3:16
membersswater shi11-May-09 3:16 
GeneralRe: Capture Buffers Pin
Klaus Fiedler11-May-09 17:05
memberKlaus Fiedler11-May-09 17:05 
NewsInfinite Loop Pin
[CC]11-Jun-08 0:42
member[CC]11-Jun-08 0:42 
GeneralRe: Infinite Loop Pin
sswater shi11-Jun-08 5:35
membersswater shi11-Jun-08 5:35 
GeneralRe: Infinite Loop Pin
[CC]12-Jun-08 2:49
member[CC]12-Jun-08 2:49 
GeneralRe: Infinite Loop Pin
sswater shi12-Jun-08 5:13
membersswater shi12-Jun-08 5:13 
GeneralRe: Infinite Loop Pin
[CC]12-Jun-08 23:46
member[CC]12-Jun-08 23:46 
QuestionFailure while using the deelx. Pin
hundikamath10-Jun-08 6:08
memberhundikamath10-Jun-08 6:08 
AnswerRe: Failure while using the deelx. Pin
sswater shi10-Jun-08 14:32
membersswater shi10-Jun-08 14:32 
GeneralRe: Failure while using the deelx. Pin
hundikamath10-Jun-08 14:54
memberhundikamath10-Jun-08 14:54 
GeneralError on Embedded Visual C++ 4.0 Pin
Shindesign29-Apr-08 9:23
memberShindesign29-Apr-08 9:23 
GeneralRe: Error on Embedded Visual C++ 4.0 Pin
sswater shi30-Apr-08 8:11
membersswater shi30-Apr-08 8:11 
QuestionCan it be wrapped into a dll? Pin
Avis p24-Dec-06 22:22
memberAvis p24-Dec-06 22:22 
AnswerRe: Can it be wrapped into a dll? Pin
sswater shi24-Dec-06 22:41
membersswater shi24-Dec-06 22:41 
GeneralRe: Can it be wrapped into a dll? Pin
Avis p24-Dec-06 23:25
memberAvis p24-Dec-06 23:25 
GeneralRe: Can it be wrapped into a dll? Pin
sswater shi25-Dec-06 21:50
membersswater shi25-Dec-06 21:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 26 Dec 2006
Article Copyright 2006 by sswater shi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid