On Fri, 9 May 2003, Clifford Heath wrote:

> While trying to build an RE to parse a shell-style regexp into an array of
> non-wild, wild, non-wild, wild, etc I found (again) that the grouping
> operator (), when followed by *, returns only the last match into the
> MatchData:

i can't answer your question, but it work this way in perl too.

> str = 'foo*bar?baz'
> regex = Regexp.new('([*?]|(?:[^*?]+))*', Regexp::EXTENDED);
>
> matches = regex.match(str)
> p matches[1..(matches.length-1)]
>
> yields:
>
> ["baz"]
>
> Annoying. I wanted ["foo", "*", "bar", "?", "baz"].
> How to do this most simply?

'foo*bar?baz'.scan /[*?]|[^*?]+/

=> ["foo", "*", "bar", "?", "baz"]

-a

--
  ====================================
  | Ara Howard
  | NOAA Forecast Systems Laboratory
  | Information and Technology Services
  | Data Systems Group
  | R/FST 325 Broadway
  | Boulder, CO 80305-3328
  | Email: ara.t.howard / fsl.noaa.gov
  | Phone:  303-497-7238
  | Fax:    303-497-7259
  ====================================