On Wed, Jun 18, 2008 at 10:15 PM, Sebastian Hungerecker
<sepp2k / googlemail.com> wrote:
> Petr Dupovnik wrote:
>> What regular expression would pull each instance of "[.*]" into a separate
>> element in an array?
>
> "some miscellaneous text [sdfsdf.wer], some more miscellaneous text
> [vbnfg.thy], and yet more text [jkhjkhjk.345]".scan(/\[[^\]]+\]/).flatten
> => ["[sdfsdf.wer]", "[vbnfg.thy]", "[jkhjkhjk.345]"]
>
> HTH,
> Sebastian
> --
> Jabber: sepp2k / jabber.org
> ICQ: 205544826
>
>


scan( /\[(.*?)\]/ ).flatten

is a shorter alternative  showing the use of the non greedy Kleene Star "*?"
But often it is indeed a good idea to be very explicit in your regular
expressions.

Cheers
Robert

-- 
http://ruby-smalltalk.blogspot.com/

---
As simple as possible, but not simpler.
Albert Einstein