# Nested repeat operator & instance\_eval

**URL:** <https://www.ruby-forum.com/t/nested-repeat-operator-instance-eval/238284>\
**Category:** Ruby\
**Created:** [December 31, 2013, 2:18pm UTC](https://www.ruby-forum.com/t/nested-repeat-operator-instance-eval/238284 "2013-12-31T14:18:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [December 31, 2013, 2:18pm UTC](https://www.ruby-forum.com/t/nested-repeat-operator-instance-eval/238284/1 "2013-12-31T14:18:06Z")

</div>

Hi,

I get a strange behavior from instance\_eval when reporting warnings on  
regular expressions, both in 1.9.3p448 and 2.0.0p353.

The file “test.rb” contains:

$-w = 2  
file = ‘foo.rb’  
code = \<\<-RUBY  
x = /]]/  
y = /[a-z]+\*/  
RUBY  
instance\_eval code, file

When run, I get:  
foo.rb:1: warning: regular expression has ‘]’ without escape: /]]/  
test.rb:7: warning: nested repeat operator + and \* was replaced with  
'_’: /[a-z]+_/

The second warning not reported as “foo.rb:2”: am I missing something,  
or should I report a bug?

– Thierry

---

<div class="post-metadata">

**Author:** ![thyresias](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a3d4f5/32.png) [@thyresias](https://www.ruby-forum.com/u/thyresias)\
**Post date:** [December 31, 2013, 11:02pm UTC](https://www.ruby-forum.com/t/nested-repeat-operator-instance-eval/238284/2 "2013-12-31T23:02:55Z")

</div>

I think Hansem is finding strange not the warning per si but the file  
and line number indication.

Why the first warning is on foo.rb:1 and the second warning is on  
test.rb:7 ?

Can you confirm this Thierry Hansem?

Abinoam Jr.

---

<div class="post-metadata">

**Author:** ![thyresias](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a3d4f5/32.png) [@thyresias](https://www.ruby-forum.com/u/thyresias)\
**Post date:** [December 31, 2013, 6:52pm UTC](https://www.ruby-forum.com/t/nested-repeat-operator-instance-eval/238284/3 "2013-12-31T18:52:56Z")

</div>

> x = /]]/  
> or should I report a bug?
> 
> – Thierry
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

I don’t believe it’s a bug in instance\_eval, I get similar output just  
running in irb.

irb(main):019:0\> x = /]]/  
(irb):19: warning: regular expression has ‘]’ without escape: /]]/  
=\> /]]/  
irb(main):020:0\> y = /[a-z]+_/  
C:/Ruby193/lib/ruby/1.9.1/irb/workspace.rb:80: warning: nested repeat  
operator +  
and \* was replaced with '_': /[a-z]+_/  
=\> /[a-z]+_/  
irb(main):021:0\>

Michael Hansen

---

<div class="post-metadata">

**Author:** ![thyresias](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a3d4f5/32.png) [@thyresias](https://www.ruby-forum.com/u/thyresias)\
**Post date:** [January 1, 2014, 3:02pm UTC](https://www.ruby-forum.com/t/nested-repeat-operator-instance-eval/238284/4 "2014-01-01T15:02:01Z")

</div>

Abinoam Jr. wrote in post #1131925:

> Can you confirm this Thierry Hansem?

It’s Thierry L. 🙂

Yes, the problem lies in the origin of the message, i.e. in the  
backtrace. I suspect it’s a problem that has already been seen, as the  
ruby ChangeLog contains:

> Mon Nov 29 22:55:24 2010 Nobuyoshi N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> - lib/uri/common.rb (URI::WFKV\_): get rid of backtrack explosion  
> by nested repeat operators. [ruby-core:33464]

– Thierry

---

<div class="post-metadata">

**Author:** ![thyresias](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a3d4f5/32.png) [@thyresias](https://www.ruby-forum.com/u/thyresias)\
**Post date:** [January 1, 2014, 3:18pm UTC](https://www.ruby-forum.com/t/nested-repeat-operator-instance-eval/238284/5 "2014-01-01T15:18:52Z")

</div>

🙂  
Heheh Sorry Thierry LAMBERT!!!  
I was fast to answer and mixed the names. Sorry.

Abinoam Jr.
