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

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

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!

On 18.09.2009 21:08, Harry wrote:

Does Ruby 1.9 explicitly support the full regexp flavor of Perl
5.10? Specifically, things like… look-around assertions, extended /

That depends on the Ruby distribution you are using. If you’re on 1.9*
then many of those features are supported.

experimental Perl regexp features such as “(?{ code })” and “(??
{ code })” .

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.

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.

Kind regards

robert

On Sep 19, 2:57 pm, Robert K. [email protected] wrote:

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.

Kind regards

    robert


remember.guy do |as, often| as.you_can - without endhttp://blog.rubybestpractices.com/

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

On Sep 19, 2:57 pm, Robert K. [email protected] wrote:

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.

Kind regards

    robert


remember.guy do |as, often| as.you_can - without endhttp://blog.rubybestpractices.com/

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

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

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.

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… :wink:

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!

On Sep 19, 2:57 pm, Robert K. [email protected] wrote:

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.

Kind regards

    robert


remember.guy do |as, often| as.you_can - without endhttp://blog.rubybestpractices.com/

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, 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?).

On 19.09.2009 17:35, Fabian S. wrote:

necessary.
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.

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… :wink:

… or find a different way to implement it in Ruby - and be surprised
how easy and concise that solution is. :slight_smile:

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)

“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… :slight_smile:

Kind regards

robert

“hackish” does not qualify a language for me.

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 :wink:

Ruby is for almost all the rest of course…

Greetz!

On Sep 20, 2:14 pm, Robert K. [email protected] wrote:

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?).

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.

On 20.09.2009 19:03, Fabian S. wrote:

“hackish” does not qualify a language for me.

well… different people, different views.

Indeed.

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 :wink:

Ruby is for almost all the rest of course…

:slight_smile: 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

On Sep 20, 10:03 pm, Fabian S. [email protected]
wrote:

my favourite for quick, dirty, < 10 lines text hacks :wink:

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 :slight_smile:

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 :wink: (Humor, and not offense,
intended.)

“hackish” does not qualify a language for me.

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 :wink:

Could you give an example of such a qd 10-liner you restrain from doing
in ruby?

mfg, simon … l

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs