[plt-scheme] Small problem with regex-replace*

From: Doug Orleans (dougorleans at gmail.com)
Date: Fri Jun 16 12:00:38 EDT 2006

Danny Yoo writes:
 > > (regexp-match "([a-zA-Z])+" "hello world")
 > ("hello" "o")
 > 
 > (The result for "([a-zA-Z])+" surprises me!)

I was surprised when I first ran into this too, but it is documented:

  When a single sub-expression occurs in a ``zero or more'' pattern
  (``*'') or a ``one or more'' pattern (``+'') and is used multiple
  times in a match, then the rightmost match associated with the
  sub-expression is returned in the list.

Seems like it would be more useful to return a list of all the
sub-expression matches, but maybe that breaks some guarantee about
space consumption?

--dougorleans at gmail.com


Posted on the users mailing list.