# Regular Expresion Error?

**URL:** <https://www.ruby-forum.com/t/regular-expresion-error/115896>\
**Category:** Ruby\
**Created:** [September 30, 2007, 12:26am UTC](https://www.ruby-forum.com/t/regular-expresion-error/115896 "2007-09-30T00:26:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Filipe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/35a633/32.png) [@Filipe](https://www.ruby-forum.com/u/Filipe)\
**Post date:** [September 30, 2007, 12:26am UTC](https://www.ruby-forum.com/t/regular-expresion-error/115896/1 "2007-09-30T00:26:03Z")

</div>

Hello all,

According to the Regular Expressions section of the following ruby  
guide:  
[Programming Ruby: The Pragmatic Programmer's Guide](http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_stdtypes.html),  
the piece of code bellow should have returned “He\<\>o”, instead of  
“No match”. Has anyone got an idea on why it isn’t working?

Notice that if I tell the interpreter how big \w should be in an  
explicit way by adding {1,1}, the expected result is given.

def showRE(a,re)  
#re = Regexp.new(re) if re.class==String  
#re=Regexp.new(re.to\_s) if re.class==Integer  
if a=~re  
“#{$`}\<\<#{$&}\>\>#{$'}”  
else  
“no match”  
end  
end

puts showRE(“Hello”, /(\w)\1/) #=\> no match  
puts showRE(“Hello”, /(\w{1,1})\1/) #=\> He\<\>o

Thanks in advance for helping

---

<div class="post-metadata">

**Author:** ![Filipe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/35a633/32.png) [@Filipe](https://www.ruby-forum.com/u/Filipe)\
**Post date:** [September 30, 2007, 12:30am UTC](https://www.ruby-forum.com/t/regular-expresion-error/115896/2 "2007-09-30T00:30:44Z")

</div>

Forgot to mention: Im running ruby 1.8.6 at Mac OS X 10.4.

---

<div class="post-metadata">

**Author:** ![Filipe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/35a633/32.png) [@Filipe](https://www.ruby-forum.com/u/Filipe)\
**Post date:** [September 30, 2007, 10:46am UTC](https://www.ruby-forum.com/t/regular-expresion-error/115896/3 "2007-09-30T10:46:49Z")

</div>

Filipe wrote:

> puts showRE(“Hello”, /(\w)\1/) #=\> no match  
> puts showRE(“Hello”, /(\w{1,1})\1/) #=\> He\<\>o

Both return “He\<\>o” for me.  
ruby 1.8.6 (2007-09-23 patchlevel 110) [x86\_64-linux]

---

<div class="post-metadata">

**Author:** ![Filipe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/35a633/32.png) [@Filipe](https://www.ruby-forum.com/u/Filipe)\
**Post date:** [September 30, 2007, 10:52am UTC](https://www.ruby-forum.com/t/regular-expresion-error/115896/4 "2007-09-30T10:52:04Z")

</div>

Filipe wrote:

> puts showRE(“Hello”, /(\w)\1/) #=\> no match  
> puts showRE(“Hello”, /(\w{1,1})\1/) #=\> He\<\>o

Both return “He\<\>o” on my machine too (Windows2000 -  
OneClickInstaller 186-25).

Wolfgang NÃ¡dasi-Donner

---

<div class="post-metadata">

**Author:** ![Filipe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/35a633/32.png) [@Filipe](https://www.ruby-forum.com/u/Filipe)\
**Post date:** [October 5, 2007, 3:36am UTC](https://www.ruby-forum.com/t/regular-expresion-error/115896/5 "2007-10-05T03:36:40Z")

</div>

On Sep 30, 5:52 am, “Wolfgang Nádasi-Donner” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Filipe wrote:
> 
> > puts showRE(“Hello”, /(\w)\1/) #=\> no match  
> > puts showRE(“Hello”, /(\w{1,1})\1/) #=\> He\<\>o
> 
> Both return “He\<\>o” on my machine too (Windows2000 -  
> OneClickInstaller 186-25).
> 
> ## Wolfgang Nádasi-Donner
> 
> Posted viahttp://www.ruby-forum.com/.

looks like the ruby interpreter I was running was jruby, under  
netbeans. Unfourtunately, I didn’t realize it at first.
