(def re-match-pat (pat str) (ac-niltree (scheme.regexp-match (scheme.pregexp pat) str))) (def re-match (pat str) (only.cdr (re-match-pat pat str))) (def re-split (delim str) (scheme.regexp-split (scheme.pregexp delim) str)) (def re-replace (pat text replacement) (scheme.regexp-replace* (scheme.pregexp pat) text replacement))
See the PLT Scheme regexp chapter for documentation on the Perl-style regular expression syntax provided by these functions.
re-match-pat
arc> (re-match-pat "def" "abcdefghi") ("def")
arc> (re-match-pat "xyz" "abcdefghi") nil
arc> (re-match-pat "(d)(ef)" "abcdefghi") ("def" "d" "ef")
re-match
arc> (re-match "xyz" "abcdefghi") nil
arc> (re-match "def" "abcdefghi") nil
arc> (re-match "(def)" "abcdefghi") ("def")
arc> (re-match "(d)(ef)" "abcdefghi") ("d" "ef")
re-split
arc> (re-split "," "abc,def,ghi") ("abc" "def" "ghi")
re-replace
arc> (re-replace "\\d" "abc1def2ghi3" "D") "abcDdefDghiD"
I thought I vaguely remembered deriving this from some regexp code in Anarki, but I couldn’t find it, so perhaps it was some other code that I borrowed from Anarki that I forgot about.
This hack depends on arc3.1 and scheme0.
Same as Arc.