--- C:\Users\Demon\Desktop\regex.d	2011-02-17 17:15:40.000000000 +0300
+++ C:\dmd2\src\phobos\std\regex.d	2011-03-01 17:54:57.213000000 +0300
@@ -228,6 +228,10 @@
             REparen,            // parenthesized subexpression
             REgoto,             // goto offset
 
+            RElookahead,
+            REneglookahead,
+            RElookbehind,
+            REneglookbehind,
             REwordboundary,
             REnotwordboundary,
             REdigit,
@@ -386,6 +390,8 @@
             case REnm:
             case REnmq:
             case REparen:
+            case RElookahead:
+            case REneglookahead:
             case REgoto:
             {
                 auto bitbuf = new OutBuffer;
@@ -589,14 +595,44 @@
 
         case '(':
             p++;
-            buf.write(REparen);
-            offset = buf.offset;
-            buf.write(cast(uint)0);             // reserve space for length
-            buf.write(re_nsub);
-            re_nsub++;
-            parseRegex(pattern, p, buf);
-            *cast(uint *)&buf.data[offset] =
-                cast(uint) (buf.offset - (offset + uint.sizeof * 2));
+            if(pattern[p] != '?')
+            {
+                buf.write(REparen);
+                offset = buf.offset;
+                buf.write(cast(uint)0);             // reserve space for length
+                buf.write(re_nsub);
+                re_nsub++;
+                parseRegex(pattern, p, buf);
+                *cast(uint *)&buf.data[offset] =
+                     cast(uint)(buf.offset - (offset + uint.sizeof * 2));
+            }
+            else if(pattern.length > p+1)
+            {
+                p++;
+                switch(pattern[p])
+                {
+                    case ':':
+                        p++;
+                        parseRegex(pattern, p, buf);
+                        break;                      // reserve space for length
+                    case '=': case '!':
+                        buf.write(pattern[p] == '=' ? RElookahead : REneglookahead);
+                        offset = buf.offset;
+                        buf.write(cast(uint)0);
+                        p++;
+                        parseRegex(pattern, p, buf);
+                        *cast(uint *)&buf.data[offset] =
+                            cast(uint)(buf.offset - (offset + uint.sizeof));
+                        break;
+                    default:
+                        error("any of :=! expected after '(?'");
+                        return 0;
+                }
+            }
+            else{
+                error("any of :=! expected after '(?'");
+                return 0;
+            }
             if (p == pattern.length || pattern[p] != ')')
             {
                 error("')' expected");
@@ -1126,6 +1162,11 @@
                 pop = &prog[0] + i + 1 + uint.sizeof * 2;
                 return starrchars(r, pop[0 .. len]);
 
+            case RElookahead: case REneglookahead:
+                len = (cast(uint *)&prog[i + 1])[0];
+                pop = &prog[0] + i + 1 + uint.sizeof ;
+                return starrchars(r, pop[0 .. len]);
+
             case REend:
                 return 0;
 
@@ -1477,6 +1518,20 @@
                             len, n, pc + 1 + uint.sizeof * 2 + len);
                     pc += 1 + uint.sizeof * 2;
                     break;
+                case RElookahead:
+                     // len, ()
+                    len = *cast(uint *)&prog[pc + 1];
+                    printf("\tRElookahead len=%d, pc=>%d\n",
+                            len, n, pc + 1 + uint.sizeof + len);
+                    pc += 1 + uint.sizeof;
+                    break;
+                case REneglookahead:
+                    // len, ()
+                    len = *cast(uint *)&prog[pc + 1];
+                    printf("\tRElookahead len=%d, pc=>%d\n",
+                            len, n, pc + 1 + uint.sizeof + len);
+                    pc += 1 + uint.sizeof;
+                    break;
 
                 case REend:
                     printf("\tREend\n");
@@ -2420,7 +2475,7 @@
                 break;
 
             case engine.REparen:
-                // len, ()
+                // len, n, ()
                 debug(regex) printf("\tREparen\n");
                 puint = cast(uint *)&engine.program[pc + 1];
                 len = puint[0];
@@ -2433,7 +2488,25 @@
                 pmatch[n + 1].endIdx = src;
                 pc = pop + len;
                 break;
-
+             
+
+            case engine.RElookahead, engine.REneglookahead:
+                // len, ()
+                debug(regex)
+                    printf("\t%s",engine.program[pc] == engine.RElookahead ?
+                        "RElookahead" : "REneglookahead");
+                len = *cast(uint*)&engine.program[pc+1];
+                pop = pc + 1 + uint.sizeof;
+                ss = src;
+                bool invert = engine.program[pc] == engine.REneglookahead ? true : false;
+                auto tmp_match = trymatch(pop,pop + len);//! changes pc
+                src = ss;//restore position in input
+                //inverse the match if negative lookahead
+                tmp_match = tmp_match ^ invert;
+                if(!tmp_match)
+                    goto Lnomatch;
+                pc = pop + len;
+                break;
             case engine.REend:
                 debug(regex) printf("\tREend\n");
                 return 1;               // successful match
