[plt-scheme] Howto regexp-split string but keep delimiters

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Nov 21 11:19:25 EST 2008

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" ".")

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.