# Oniguruma: Different result in ruby 1.9.1 and 1.8.7

**URL:** <https://rubytalk.org/t/oniguruma-different-result-in-ruby-1-9-1-and-1-8-7/55235>\
**Category:** ruby-talk\
**Created:** [4 September 2009 00:33 UTC](https://rubytalk.org/t/oniguruma-different-result-in-ruby-1-9-1-and-1-8-7/55235 "2009-09-04T00:33:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![miguelfteixeira](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/miguelfteixeira/32/2357_2.png) [@miguelfteixeira](https://rubytalk.org/u/miguelfteixeira)\
**Post date:** [4 September 2009 00:33 UTC](https://rubytalk.org/t/oniguruma-different-result-in-ruby-1-9-1-and-1-8-7/55235/1 "2009-09-04T00:33:26Z")

</div>

Hi,

I have the following regular expression created in ruby 1.9.1:

/(?:(?:\$(?'name1'[\w\s\']+)(?:(?'name2'(?:created|developed)[\w\s]+)(?name3'(?:in|at)[\w\s]+)))|(?:\$(?'name1'[\w\s\']+)(?'name2'(:?created|developed)[\w\s]+))|(?:\$(?'name1'[\w\s\']+)(?'name3'(?:in|at)[\w\s]+)))(?:\.(?'name4'[\w\s]+))?/.match(str)

To use Oniguruma i have installed the following gem:

> **[geoffgarside/oniguruma](https://github.com/geoffgarside/oniguruma/tree/master)**
>
> Re-implementation of the oniguruma gem in pure C. Also aims to be compatible with more versions of Oniguruma

(also tried with this solution:  
[http://www.goodbyehelicopter.com/2008/02/20/install-oniguruma-on-os-x/](http://www.goodbyehelicopter.com/2008/02/20/install-oniguruma-on-os-x/))

After the installation of Oniguruma i have created the following regular  
expression in ruby 1.8.7:  
Oniguruma::ORegexp.new('(?:(?:\$(?\'name1\'[\w\s\']+)(?:(?\'name2\'(?:created|developed)[\w\s]+)(?\'name3\'(?:in|at)[\w\s]+)))|(?:\$(?\'name1\'[\w\s\']+)(?\'name2\'(:?created|developed)[\w\s]+))|(?:\$(?\'name1\'[\w\s\']+)(?\'name3\'(?:in|at)[\w\s]+)))(?:\.(?\'name4\'[\w\s]+))?').match(str)

My problem is that the result in ruby 1.8.7 is different from the result  
in 1.9.1.  
Anyone has an idea about what's going on?

I also tried to substitute ?\'name1\' with ?\<name1\>

Thanks,

> **···**
>
> --  
> Miguel Teixeira  
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Aaron\_Patterson1](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@Aaron\_Patterson1](https://rubytalk.org/u/Aaron_Patterson1)\
**Post date:** [4 September 2009 00:49 UTC](https://rubytalk.org/t/oniguruma-different-result-in-ruby-1-9-1-and-1-8-7/55235/2 "2009-09-04T00:49:25Z")

</div>

That expression is rather long. Have you tried reducing the regular expression to the smallest possible case that will make it break?

> **···**
>
> On Sep 3, 2009, at 5:33 PM, Miguel Teixeira wrote:
> 
> > Hi,
> > 
> > I have the following regular expression created in ruby 1.9.1:
> > 
> > /(?:(?:\$(?'name1'[\w\s\']+)(?:(?'name2'(?:created|developed)[\w\s]+)(?name3'(?:in|at)[\w\s]+)))|(?:\$(?'name1'[\w\s\']+)(?'name2'(:?created\>developed)[\w\s]+))|(?:\$(?'name1'[\w\s\']+)(?'name3'(?:in|at)[\w\s]+)))(?:\.(?'name4'[\w\s]+))?/.match(str)
> > 
> > To use Oniguruma i have installed the following gem:  
> > [GitHub - geoffgarside/oniguruma: Re-implementation of the oniguruma gem in pure C. Also aims to be compatible with more versions of Oniguruma](http://github.com/geoffgarside/oniguruma/tree/master)
> > 
> > (also tried with this solution:  
> > [http://www.goodbyehelicopter.com/2008/02/20/install-oniguruma-on-os-x/\](http://www.goodbyehelicopter.com/2008/02/20/install-oniguruma-on-os-x/%5C))
> > 
> > After the installation of Oniguruma i have created the following regular  
> > expression in ruby 1.8.7:  
> > Oniguruma::ORegexp.new('(?:(?:\$(?\'name1\'[\w\s\']+)(?:(?\'name2\'(?:created|developed)[\w\s]+)(?\'name3\'(?:in|at)[\w\s]+)))|(?:\$(?\'name1\'[\w\s\']+)(?\'name2\'(:?created|developed)[\w\s]+))|(?:\$(?\'name1\'[\w\s\']+)(?\'name3\'(?:in|at)[\w\s]+)))(?:\.(?\'name4\'[\w\s]+))?').match(str)
> > 
> > My problem is that the result in ruby 1.8.7 is different from the result  
> > in 1.9.1.  
> > Anyone has an idea about what's going on?
> > 
> > I also tried to substitute ?\'name1\' with ?\<name1\>
> 
> ---  
> Aaron Patterson  
> [http://tenderlovemaking.com](http://tenderlovemaking.com)

---

<div class="post-metadata">

**Author:** ![Robert\_K1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/robert_k1/32/1830_2.png) [@Robert\_K1](https://rubytalk.org/u/Robert_K1)\
**Post date:** [4 September 2009 14:29 UTC](https://rubytalk.org/t/oniguruma-different-result-in-ruby-1-9-1-and-1-8-7/55235/3 "2009-09-04T14:29:44Z")

</div>

What differences did you observe? Against which text did you match?

To simplify your tests I would create both regular expressions via the  
string method. Then you can be sure to use the same string and not  
fall culprit of some conversion or typing errors.

Kind regards

robert

> **···**
>
> 2009/9/4 Miguel Teixeira \<miguelfteixeira@gmail.com\>:
> 
> > I have the following regular expression created in ruby 1.9.1:
> > 
> > /(?:(?:\$(?'name1'[\w\s\']+)(?:(?'name2'(?:created|developed)[\w\s]+)(?name3'(?:in|at)[\w\s]+)))|(?:\$(?'name1'[\w\s\']+)(?'name2'(:?created|developed)[\w\s]+))|(?:\$(?'name1'[\w\s\']+)(?'name3'(?:in|at)[\w\s]+)))(?:\.(?'name4'[\w\s]+))?/.match(str)
> > 
> > To use Oniguruma i have installed the following gem:  
> > [GitHub - geoffgarside/oniguruma: Re-implementation of the oniguruma gem in pure C. Also aims to be compatible with more versions of Oniguruma](http://github.com/geoffgarside/oniguruma/tree/master)
> > 
> > (also tried with this solution:  
> > [http://www.goodbyehelicopter.com/2008/02/20/install-oniguruma-on-os-x/\](http://www.goodbyehelicopter.com/2008/02/20/install-oniguruma-on-os-x/%5C))
> > 
> > After the installation of Oniguruma i have created the following regular  
> > expression in ruby 1.8.7:  
> > Oniguruma::ORegexp.new('(?:(?:\$(?\'name1\'[\w\s\']+)(?:(?\'name2\'(?:created|developed)[\w\s]+)(?\'name3\'(?:in|at)[\w\s]+)))|(?:\$(?\'name1\'[\w\s\']+)(?\'name2\'(:?created|developed)[\w\s]+))|(?:\$(?\'name1\'[\w\s\']+)(?\'name3\'(?:in|at)[\w\s]+)))(?:\.(?\'name4\'[\w\s]+))?').match(str)
> > 
> > My problem is that the result in ruby 1.8.7 is different from the result  
> > in 1.9.1.  
> > Anyone has an idea about what's going on?
> 
> --  
> remember.guy do |as, often| as.you\_can - without end  
> [http://blog.rubybestpractices.com/](http://blog.rubybestpractices.com/)

---

<div class="post-metadata">

**Author:** ![miguelfteixeira](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/miguelfteixeira/32/2357_2.png) [@miguelfteixeira](https://rubytalk.org/u/miguelfteixeira)\
**Post date:** [4 September 2009 14:45 UTC](https://rubytalk.org/t/oniguruma-different-result-in-ruby-1-9-1-and-1-8-7/55235/4 "2009-09-04T14:45:08Z")

</div>

Hi robert,

The problem is that in ruby 1.8.7 is impossible (?) to use string method  
with oniguruma (the default regular expression engine is different).

The differences that i observe is the match's for the cases where the  
(created|developed) and (in|at) groups should be matched.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Robert\_K1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/robert_k1/32/1830_2.png) [@Robert\_K1](https://rubytalk.org/u/Robert_K1)\
**Post date:** [4 September 2009 17:21 UTC](https://rubytalk.org/t/oniguruma-different-result-in-ruby-1-9-1-and-1-8-7/55235/5 "2009-09-04T17:21:54Z")

</div>

> The problem is that in ruby 1.8.7 is impossible (?) to use string method with oniguruma (the default regular expression engine is different).

Apparently you are not getting my point - maybe I wasn't clear enough. I suggested to \*create\* the regular expression via a String, i.e. Regexp.new(s) and Oniguruma::ORegexp.new(s).

> The differences that i observe is the match's for the cases where the (created|developed) and (in|at) groups should be matched.

What difference do you observe? You are not really providing much information to answer your question. You could do yourself a favor and simply post a script or IRB session showing the different behavior.

[http://catb.org/~esr/faqs/smart-questions.html](http://catb.org/~esr/faqs/smart-questions.html)

Cheers

&nbsp;&nbsp;robert

> **···**
>
> On 04.09.2009 16:45, Miguel Teixeira wrote:
> 
> --  
> remember.guy do |as, often| as.you\_can - without end  
> [http://blog.rubybestpractices.com/](http://blog.rubybestpractices.com/)

---

<div class="post-metadata">

**Author:** ![miguelfteixeira](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/miguelfteixeira/32/2357_2.png) [@miguelfteixeira](https://rubytalk.org/u/miguelfteixeira)\
**Post date:** [5 September 2009 11:14 UTC](https://rubytalk.org/t/oniguruma-different-result-in-ruby-1-9-1-and-1-8-7/55235/6 "2009-09-05T11:14:31Z")

</div>

Hi robert,

I get the same result when trying the match via Regexp.new.

Maybe the version of origuruma is different, i will try to create a  
different regular expression (more simple) this times using ruby 1.8.7  
regular expression engine.

Thanks for the help.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
