[racket] Regexp question: Pattern that can match everything to left of first pattern?

From: John Clements (clements at brinckerhoff.org)
Date: Wed May 8 13:38:33 EDT 2013

On May 8, 2013, at 10:25 AM, Don Green wrote:

> Regexp question: Is there a pattern that can match everything to left of first pattern?
> 
> (regexp-match #rx"x.*" "12x4x6") ; => '("x4x6") ;returns everything to right of first pattern x
> 
> (regexp-match #rx"___" "12x4x6") ; => '("12x") ;returns everything to left of first pattern x
> 

The traditional way to do this would be to match a sequence of non-x's followed by an x, like this:

#lang racket

(regexp-match #rx"[^x]*x" "12x4x6") ; => '("12x")

Things get a bit more interesting if you put a more complex pattern in place of a simple "x".

John Clements

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130508/a70b5e8a/attachment.html>

Posted on the users mailing list.