Racket regular-expression matching

Posted by Inaimathi on Stack Overflow See other posts from Stack Overflow or by Inaimathi
Published on 2010-05-22T16:57:23Z Indexed on 2010/05/22 17:00 UTC
Read the original article Hit count: 311

Filed under:
|
|

I'm trying to create a regex that matches the inverse of a certain string type (so, strings not ending in ".js", for example).

According to the documentation, that should be the expression #rx"(?!\\.js$)", but it doesn't seem to work. To test it out, I have this function:

(define (match-test regex)
    (map (lambda (text)
           (regexp-match? regex text))
         '("foo.js" "bar.css" "baz.html" "mumble.gif" "foobar")))

(match-test #rx"\\.js$") returns (#t #f #f #f #f) as expected, but (match-test #rx"(?!\\.js$)") returns (#t #t #t #t #t), where I would expect (#f #t #t #t #t).

What am I doing wrong, and how do I actually get a regex in Racket to express the idea "match anything which does not contain [x]"?

© Stack Overflow or respective owner

Related posts about regex

Related posts about Scheme