Newbie: Are Ruby regexp's a subset, superset, or equal to Perl's?

Discussion in 'Ruby' started by Harry, Sep 18, 2009.

  1. Harry

    Harry Guest

    Hi,
    Does Ruby 1.9 explicitly support the _full_ regexp flavor of Perl
    5.10? Specifically, things like... look-around assertions, extended /
    experimental Perl regexp features such as "(?{ code })" and "(??
    { code })" .

    Many thanks,
    /HS
     
    Harry, Sep 18, 2009
    #1
    1. Advertisements

  2. [Note: parts of this message were removed to make it a legal post.]

    you might want to look at oniguruma's pages:
    http://github.com/jasherai/oniguruma

    quote

    * Support for named groups, look-ahead, look-behind, and other
    cool features!
    * Support for other regexp syntaxes (Perl, Python, Java, etc.)

    == Lacking features compare with perl 5.8.0

    * \N{name}
    * \l,\u,\L,\U, \X, \C
    * (?{code})
    * (??{code})
    * (?(condition)yes-pat|no-pat)
    * \Q...\E

    This is effective on ONIG_SYNTAX_PERL and ONIG_SYNTAX_JAVA.

    unquote


    Greetz!
     
    Fabian Streitel, Sep 18, 2009
    #2
    1. Advertisements

  3. That depends on the Ruby distribution you are using. If you're on 1.9*
    then many of those features are supported.
    Ruby's RX engine won't execute any code embedded in the expression
    AFAIK. I second Fabian: look at the docs.

    But one thing is sure: you cannot expect to copy a Perl regexp over to
    Ruby and use it as before, especially if advanced features are used.

    <soapbox>Personally I did not have the need for embedded code in regular
    expressions yet. If your pattern matching becomes that complex, chances
    are that a different approach (e.g. code /outside/ the rx) is better
    maintainable. My impression is that Perl has a tendency to include more
    and more obscure features which makes it less and less readable over
    time. When I used it on a daily basis I was pretty fluent but nowadays
    looking at Perl code gives me the creeps.</soapbox>

    Kind regards

    robert
     
    Robert Klemme, Sep 19, 2009
    #3
  4. Harry

    Harry Guest

    Thanks, Robert. And, Fabian too... for the taking the time to reply!

    Robert, I fully agree with your 'soapbox' content above. I use Perl
    mostly for my text processing needs, and am seriously considering
    switching to Ruby, mainly for the latter's elegance and simplicity
    overall. I admit, I have absolutely no practical need to use any of
    those experimental portions of Perl regexp as of today. However, just
    the thought that they are there in your new language for your use if
    and when you need them can be very comforting indeed. Hence the
    question. Anyways, I'll manage without 'em for now.

    An appeal to Ruby Development Team: If Perl has no patent over its
    regexp spec (I believe Perl is completely free), then the Ruby
    Development Team should simply lift wholesale the whole blessed regexp
    spec out of Perl (including the code) and support it in Ruby. I'm sure
    Rubyists in general would welcome this. Basically: If you don't need
    something, just don't use it; however, it's available for the rest.

    Best regards,
    /HS
     
    Harry, Sep 19, 2009
    #4
  5. Harry

    Harry Guest

    Thanks, Robert. And, Fabian too... for the taking the time to reply!

    Robert, I fully agree with your 'soapbox' content above. I use Perl
    mostly for my text processing needs, and am seriously considering
    switching to Ruby, mainly for the latter's elegance and simplicity
    overall. I admit, I have absolutely no practical need to use any of
    those experimental portions of Perl regexp as of today. However, just
    the thought that they are there in your new language for your use if
    and when you need them can be very comforting indeed. Hence the
    question. Anyways, I'll manage without 'em for now.

    An appeal to Ruby Development Team: If Perl has no patent over its
    regexp spec (I believe Perl is completely free), then the Ruby
    Development Team should simply lift wholesale the whole blessed regexp
    spec out of Perl (including the code) and support it in Ruby. I'm sure
    Rubyists in general would welcome this. Basically: If you don't need
    something, just don't use it; however, it's available for the rest.

    Best regards,
    /HS
     
    Harry, Sep 19, 2009
    #5
  6. Harry

    Harry Guest

    Thanks, Robert. And, Fabian too... for the taking the time to reply!

    Robert, I fully agree with your 'soapbox' content above. I use Perl
    mostly for my text processing needs, and am seriously considering
    switching to Ruby, mainly for the latter's elegance and simplicity
    overall. I admit, I have absolutely no practical need to use any of
    those experimental portions of Perl regexp as of today. However, just
    the thought that they are there in your new language for your use if
    and when you need them can be very comforting indeed. Hence the
    question. Anyways, I'll manage without 'em for now.

    An appeal to Ruby Development Team: If Perl has no patent over its
    regexp spec (I believe Perl is completely free), then the Ruby
    Development Team should simply lift wholesale the whole blessed regexp
    spec out of Perl (including the code) and support it in Ruby. I'm sure
    Rubyists in general would welcome this. Basically: If you don't need
    something, just don't use it; however, it's available for the rest.

    Best regards,
    /HS
     
    Harry, Sep 19, 2009
    #6
  7. [Note: parts of this message were removed to make it a legal post.]

    hehe, thanks for the rating... I didn't even know there was such a thing...

    An appeal to Ruby Development Team: If Perl has no patent over its
    Hm, IMHO that's not necessary. Except for lookaround, I had no need
    for any more advanced regexp features in Ruby 1.8.7 and with Oniguruma
    that one need will be satisfied in 1.9, so I don't see why that should be
    necessary.

    Oniguruma is a great regexp implementation, and if you really need those
    2 or 3 features that aren't in there -- then you should probably do that one
    script in perl... ;-)

    After all, it is still a nice language that lets you do some stuff
    wonderfully
    hackishly, so IMHO it has it's place (I for myself love to do hackish stuff
    from time to time -- keeps me from doing that in Ruby, where I don't want
    that)

    Greetz and a nice weekend!
     
    Fabian Streitel, Sep 19, 2009
    #7
  8. Harry, your posting appeared three times in comp.lang.ruby. If
    possible, please try to avoid that. If the cause is not on your side we
    should probably find out what went wrong (gateway?).

    I agree 100%: lookaround was _the_ feature I missed in 1.8 land - and
    since it's there in 1.9 (among other nice improvements, most notably
    execution speed) I am quite happy with the state of affairs.
    .... or find a different way to implement it in Ruby - and be surprised
    how easy and concise that solution is. :)
    "hackish" does not qualify a language for me. The most compelling
    reason for me to use Perl would be the presence of a library in CPAN
    that I otherwise had to painfully recode in Ruby. OTOH, it may actually
    happen that I find the recode fun and turn it into a Gem for wider
    use... :)

    Kind regards

    robert
     
    Robert Klemme, Sep 20, 2009
    #8
  9. [Note: parts of this message were removed to make it a legal post.]
    well... different people, different views. I personally think that almost
    any language is good for something, but none for everything -- and Perl is
    my favourite for quick, dirty, < 10 lines text hacks ;-)

    Ruby is for almost all the rest of course...

    Greetz!
     
    Fabian Streitel, Sep 20, 2009
    #9
  10. Harry

    Harry Guest

    Typically, when I send a message (to any newsgroup in general), I hit
    browser refresh / F5 to see my post. With the last post of mine, I
    don't particularly remember what exactly I did but (for some wierd
    reason) when I hit F5 I got the Http Post confirmation message with OK/
    Cancel options to which, yes, I said OK a few times (3). Later, I was
    told that my session (with google.groups.com) had expired and that I
    needed to log back in, which I did.

    Sorry for this one, I will try to be more wakeful next time.
     
    Harry, Sep 21, 2009
    #10
  11. Harry

    Harry Guest

    I think, the operative word here is _dirty_.

    When we programmers call some piece of code a 'quick and dirty'
    solution, a 'nasty hack'... typically, reverse is the case: it is
    quick and elegant and nifty instead of nasty. We are, I guess,
    indirectly/subtly praising ourselves :)

    But with Perl the story is different. If someone tells me that they
    have implemented a 'quick and dirty hack... for now' in Perl, I will
    take the word 'dirty' literally ;-) (Humor, and not offense,
    intended.)
     
    Harry, Sep 21, 2009
    #11
  12. :) With me it is different: whenever I need to write together a quick
    script I turn to Ruby (or Bourne shell if Ruby is not present on that
    system).

    Cheers

    robert
     
    Robert Klemme, Sep 21, 2009
    #12
  13. Could you give an example of such a qd 10-liner you restrain from doing
    in ruby?

    mfg, simon .... l
     
    Simon Krahnke, Sep 23, 2009
    #13
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.