Oniguruma: Different result in ruby 1.9.1 and 1.8.7

Discussion in 'Ruby' started by Miguel Teixeira, Sep 4, 2009.

  1. 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:
    http://github.com/geoffgarside/oniguruma/tree/master

    (also tried with this solution:
    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/.
    Miguel Teixeira, Sep 4, 2009
    #1
    1. Advertising

  2. 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:
    > http://github.com/geoffgarside/oniguruma/tree/master
    >
    > (also tried with this solution:
    > 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>


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

    ---
    Aaron Patterson
    http://tenderlovemaking.com
    Aaron Patterson, Sep 4, 2009
    #2
    1. Advertising

  3. 2009/9/4 Miguel Teixeira <>:
    > I have the following regular expression created in ruby 1.9.1:
    >
    > /(?:(?:\$(?'name1'[\w\s\']+)(?:(?'name2'(?:created|developed)[\w\s]+)(?na=

    me3'(?:in|at)[\w\s]+)))|(?:\$(?'name1'[\w\s\']+)(?'name2':)?created|develop=
    ed)[\w\s]+))|(?:\$(?'name1'[\w\s\']+)(?'name3'(?:in|at)[\w\s]+)))(?:\.(?'na=
    me4'[\w\s]+))?/.match(str)
    >
    > To use Oniguruma i have installed the following gem:
    > http://github.com/geoffgarside/oniguruma/tree/master
    >
    > (also tried with this solution:
    > 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\'(?:cre=

    ated|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?


    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

    --=20
    remember.guy do |as, often| as.you_can - without end
    http://blog.rubybestpractices.com/
    Robert Klemme, Sep 4, 2009
    #3
  4. 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/.
    Miguel Teixeira, Sep 4, 2009
    #4
  5. On 04.09.2009 16:45, Miguel Teixeira wrote:
    > 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

    Cheers

    robert

    --
    remember.guy do |as, often| as.you_can - without end
    http://blog.rubybestpractices.com/
    Robert Klemme, Sep 4, 2009
    #5
  6. 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/.
    Miguel Teixeira, Sep 5, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Strandgaard

    regexp unlimited: Ruby's vs Oniguruma

    Simon Strandgaard, Nov 13, 2003, in forum: Ruby
    Replies:
    2
    Views:
    82
    Mark Wilson
    Nov 17, 2003
  2. Michael Tan
    Replies:
    32
    Views:
    973
    Ara.T.Howard
    Jul 21, 2005
  3. Wolfgang Nádasi-Donner
    Replies:
    8
    Views:
    168
    Wolfgang Nádasi-Donner
    Jul 31, 2005
  4. Ashley Moran

    Compile ruby with oniguruma on OS X

    Ashley Moran, Nov 22, 2006, in forum: Ruby
    Replies:
    2
    Views:
    109
    Ashley Moran
    Nov 24, 2006
  5. Steve Riley

    Oniguruma and Ruby-1.8.6

    Steve Riley, Apr 1, 2007, in forum: Ruby
    Replies:
    0
    Views:
    96
    Steve Riley
    Apr 1, 2007
Loading...

Share This Page