[plt-scheme] Howto regexp-split string but keep delimiters
On Nov 21, Eli Barzilay wrote:
> On Nov 21, Erich Rast wrote:
> > Hello all,
> >
> > I need to split a large string into separate words using a regexp, but
> > need to keep non-whitespace delimiters:
> >
> > "Ab, c, dd,hello." ==> ("Ab" "," "c" "," "dd" "," "hello" ".")
> >
> > Can this be done using regexp-split? How?
>
> It's easier to do with regexp-match:
>
> > (regexp-match* #px"[\\w]+|[^\\s\\w]" "Ab, c, dd,hello.")
> ("Ab" "," "c" "," "dd" "," "hello" ".")
I should have said that it was difficult to do that with
`regexp-split' for a technical reason regarding a problem that bugged
me for a while. I've finally managed to solve it -- if you get
today's nightly build, then you can get the same result more easily
with `regexp-split':
> (regexp-split #px"\\b| +" "Ab, c, dd,hello.")
("Ab" "," "c" "," "dd" "," "hello" ".")
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!