Jos Backus wrote:

> Isn't it too bad a non-match raises an IndexError instead of returning nil?
> 
> irb(main):006:0> if str[/(hello)/, 1] = ""; puts "match", $1; end
> match
> hello
> => nil
> irb(main):007:0> if str[/(hallo)/, 1] = ""; puts "match", $1; end
> IndexError: regexp not matched
>         from (irb):7:in `[]='
>         from (irb):7
> irb(main):008:0> 

Not sure why you'd want to do that (.slice!() works better IMHO), but 
perhaps you can do it like this:

"hello"[/((?:hallo)?)/, 1] = ""