[racket] Regexp question: Pattern that can match everything to left of first pattern?
An hour ago, John Clements wrote:
>
> 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".
An easy hack is using non-greedy operators:
-> (regexp-match #rx".*?===" "some=text=here===but=not=this===text")
'("some=text=here===")
-> (regexp-match #rx".*===" "some=text=here===but=not=this===text")
'("some=text=here===but=not=this===")
(But they can lead to dangerous inefficiencies.)
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!