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

From: Norman Gray (norman at astro.gla.ac.uk)
Date: Wed May 8 14:42:55 EDT 2013

Don, hello.

On 2013 May 8, at 18:25, Don Green <infodeveloperdon at gmail.com> wrote:

> (regexp-match #rx"___" "12x4x6") ; => '("12x") ;returns everything to left
> of first pattern x

Orthogonally to John's answer (which is all about matching the thing you want), you can aim to match the pattern you want to terminate the thing you want:

Welcome to Racket v5.3.3.
> (regexp-match #rx"(.*)x4x" "12x4x67")
'("12x4x" "12")
> (regexp-match #rx"(.*)x.x" "12x45x67x8x90")
'("12x45x67x8x" "12x45x67")
> (regexp-match #rx"(.*)x.x" "12x45xx67xxx90")
'("12x45xx67xxx" "12x45xx67")

Norman


-- 
Norman Gray  :  http://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK



Posted on the users mailing list.