diff --git a/basis/regexp/regexp-tests.factor b/basis/regexp/regexp-tests.factor index fa907011fd..f7d3dae3f3 100644 --- a/basis/regexp/regexp-tests.factor +++ b/basis/regexp/regexp-tests.factor @@ -211,8 +211,8 @@ IN: regexp-tests [ f ] [ "aaaxb" "a+ab" matches? ] unit-test [ t ] [ "aaacb" "a+cb" matches? ] unit-test -[ 3 ] [ "aaacb" "a*" match-index-head ] unit-test -[ 2 ] [ "aaacb" "aa?" match-index-head ] unit-test +[ "aaa" ] [ "aaacb" "a*" match-head >string ] unit-test +[ "aa" ] [ "aaacb" "aa?" match-head >string ] unit-test [ t ] [ "aaa" R/ AAA/i matches? ] unit-test [ f ] [ "aax" R/ AAA/i matches? ] unit-test @@ -310,8 +310,8 @@ IN: regexp-tests [ "a" ] [ "ba" "(?<=b)(?<=b)a" match-head >string ] unit-test [ "a" ] [ "cab" "(?<=c)a(?=b)" match-head >string ] unit-test -[ 3 ] [ "foobar" "foo(?=bar)" match-index-head ] unit-test -[ f ] [ "foobxr" "foo(?=bar)" match-index-head ] unit-test +[ 3 ] [ "foobar" "foo(?=bar)" match-head length ] unit-test +[ f ] [ "foobxr" "foo(?=bar)" match-head ] unit-test ! Bug in parsing word [ t ] [ "a" R' a' matches? ] unit-test @@ -424,8 +424,8 @@ IN: regexp-tests [ 1 ] [ "a\r" R/ a$/m count-matches ] unit-test [ 1 ] [ "a\r\n" R/ a$/m count-matches ] unit-test -[ f ] [ "foobxr" "foo\\z" match-index-head ] unit-test -[ 3 ] [ "foo" "foo\\z" match-index-head ] unit-test +[ f ] [ "foobxr" "foo\\z" match-head ] unit-test +[ 3 ] [ "foo" "foo\\z" match-head length ] unit-test ! [ t ] [ "foo" "\\bfoo\\b" matches? ] unit-test ! [ t ] [ "afoob" "\\Bfoo\\B" matches? ] unit-test diff --git a/basis/regexp/regexp.factor b/basis/regexp/regexp.factor index aacd888ccb..94bbc2af58 100644 --- a/basis/regexp/regexp.factor +++ b/basis/regexp/regexp.factor @@ -44,14 +44,17 @@ M: lookbehind question>quot ! Returns ( index string -- ? ) ! and that string is a string. dup dfa>> execute( index string regexp -- i/f ) ; -: match-index-head ( string regexp -- index/f ) - [ 0 ] 2dip [ check-string ] dip match-index-from ; +GENERIC: end/start ( string regexp -- end start ) +M: regexp end/start drop length 0 ; +M: reverse-regexp end/start drop length 1- -1 swap ; PRIVATE> : matches? ( string regexp -- ? ) - dupd match-index-head - [ swap length = ] [ drop f ] if* ; + [ end/start ] 2keep + [ check-string ] dip + match-index-from + [ swap = ] [ drop f ] if* ;