     dup '[
         dup \ next-initial-word = [
             drop _ [ compile-regexp dfa>> ] [ reverse-regexp? ] bi
-            '[ _ '[ _ _ execute ] _ next-match ]
+            '[ _ _ next-match ]
             (( i string regexp -- i start end string )) simple-define-temp
         ] when
     ] change-next-match ;

        i' string regexp quot (each-match)
    ] [ 3drop ] if ; inline recursive

PRIVATE>

: prepare-match-iterator ( string regexp -- i string regexp )
    [ check-string ] dip [ end/start nip ] 2keep ; inline

: each-match ( string regexp quot: ( start end string -- ) -- )
    [ prepare-match-iterator ] dip (each-match) ; inline


<PRIVATE

:: (next-match) ( i string regexp word: ( i string -- j ) reverse? -- i start end ? )
    i string regexp word execute dup [| j |
        j i j
        reverse? [ swap [ 1+ ] bi@ ] when
        string
    ] [ drop f f f f ] if ; inline

: search-range ( i string reverse? -- seq )
    [ drop 0 [a,b] ] [ length [a,b) ] if ; inline

:: next-match ( i string regexp word reverse? -- i start end ? )
    f f f f
    i string reverse? search-range
    [ [ 2drop 2drop ] dip string regexp word reverse? (next-match) dup ] find 2drop ; inline

: do-next-match ( i string regexp -- i start end ? )
    dup next-match>>
