diff --git a/basis/regexp/regexp-tests.factor b/basis/regexp/regexp-tests.factor index c2f7bb5bc6..1cd9a2392e 100644 --- a/basis/regexp/regexp-tests.factor +++ b/basis/regexp/regexp-tests.factor @@ -287,9 +287,13 @@ IN: regexp-tests [ { "1" "2" "3" "4" } ] [ "1ABC2DEF3GHI4" R/ [A-Z]+/ re-split [ >string ] map ] unit-test -[ { "1" "2" "3" "4" } ] +[ { "1" "2" "3" "4" "" } ] [ "1ABC2DEF3GHI4JK" R/ [A-Z]+/ re-split [ >string ] map ] unit-test +[ { "" } ] [ "" R/ =/ re-split [ >string ] map ] unit-test + +[ { "a" "" } ] [ "a=" R/ =/ re-split [ >string ] map ] unit-test + [ { "ABC" "DEF" "GHI" } ] [ "1ABC2DEF3GHI4" R/ [A-Z]+/ all-matches [ >string ] map ] unit-test @@ -299,16 +303,16 @@ IN: regexp-tests [ 0 ] [ "123" R/ [A-Z]+/ count-matches ] unit-test -[ "1.2.3.4" ] +[ "1.2.3.4." ] [ "1ABC2DEF3GHI4JK" R/ [A-Z]+/ "." re-replace ] unit-test - -[ "-- title --" ] [ "== title ==" "=" "-" re-replace ] unit-test + +[ "-- title --" ] [ "== title ==" R/ =/ "-" re-replace ] unit-test /* ! FIXME [ f ] [ "ab" "a(?!b)" first-match ] unit-test [ "a" ] [ "ac" "a(?!b)" first-match >string ] unit-test -! [ t ] [ "fxxbar" "(?!foo).{3}bar" matches? ] unit-test +[ t ] [ "fxxbar" "(?!foo).{3}bar" matches? ] unit-test [ f ] [ "foobar" "(?!foo).{3}bar" matches? ] unit-test [ "a" ] [ "ab" "a(?=b)(?=b)" first-match >string ] unit-test [ "a" ] [ "ba" "a(?<=b)(?<=b)" first-match >string ] unit-test @@ -319,7 +323,7 @@ IN: regexp-tests */ ! Bug in parsing word -[ t ] [ "a" R' a' matches? ] unit-test +[ t ] [ "a" R' a' matches? ] unit-test ! Convert to lowercase until E [ f ] [ "AA" R/ \LAA\E/ matches? ] unit-test diff --git a/basis/regexp/regexp.factor b/basis/regexp/regexp.factor index c615719cc4..86f978373b 100644 --- a/basis/regexp/regexp.factor +++ b/basis/regexp/regexp.factor @@ -61,8 +61,11 @@ IN: regexp dupd first-match [ split1-slice swap ] [ "" like f swap ] if* ; +: (re-split) ( string regexp -- ) + over [ [ re-cut , ] keep (re-split) ] [ 2drop ] if ; + : re-split ( string regexp -- seq ) - [ dup length 0 > ] swap '[ _ re-cut ] [ ] produce nip ; + [ (re-split) ] { } make ; : re-replace ( string regexp replacement -- result ) [ re-split ] dip join ;