Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Newbie: Are Ruby regexp's a subset, superset, or equal to Perl's?

Reply
Thread Tools

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

 
 
Harry
Guest
Posts: n/a
 
      09-18-2009
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
 
Reply With Quote
 
 
 
 
Fabian Streitel
Guest
Posts: n/a
 
      09-18-2009
[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!

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      09-19-2009
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.

<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

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
Harry
Guest
Posts: n/a
 
      09-19-2009
On Sep 19, 2:57*pm, Robert Klemme <shortcut...@googlemail.com> wrote:
> 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.
>
> <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
>
> --
> 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
 
Reply With Quote
 
Harry
Guest
Posts: n/a
 
      09-19-2009
On Sep 19, 2:57*pm, Robert Klemme <shortcut...@googlemail.com> wrote:
> 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.
>
> <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
>
> --
> 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
 
Reply With Quote
 
Harry
Guest
Posts: n/a
 
      09-19-2009
On Sep 19, 2:57*pm, Robert Klemme <shortcut...@googlemail.com> wrote:
> 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.
>
> <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
>
> --
> 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
 
Reply With Quote
 
Fabian Streitel
Guest
Posts: n/a
 
      09-19-2009
[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
> 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...

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!

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      09-20-2009

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 Streitel wrote:
> 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.


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


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

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

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
Fabian Streitel
Guest
Posts: n/a
 
      09-20-2009
[Note: parts of this message were removed to make it a legal post.]

>
> "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

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

Greetz!

 
Reply With Quote
 
Harry
Guest
Posts: n/a
 
      09-21-2009
On Sep 20, 2:14*pm, Robert Klemme <shortcut...@googlemail.com> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ruby doesn't need equal's signs for assigment? Peter Alvin Ruby 3 09-02-2008 11:35 AM
Internet Sharing: Equal upload speeds but un-equal download speeds =?Utf-8?B?TkpU?= Wireless Networking 3 09-15-2007 06:22 AM
#!/usr/bin/ruby , #!/usr/bin/ruby -w , #!/usr/bin/ruby -T?, #!/usr/bin/ruby -T1... anne001 Ruby 1 04-23-2006 03:02 PM
driver irql not less or equal =?Utf-8?B?Y2VudHVyaWFu?= Wireless Networking 2 03-11-2005 08:30 PM
Re: OSPF Equal cost balancing in serie 2500 routers Aaron Woody Cisco 0 10-20-2003 02:42 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57