# Ruby Regexp implementation?

**URL:** <https://www.ruby-forum.com/t/ruby-regexp-implementation/185058>\
**Category:** Ruby\
**Created:** [March 12, 2010, 7:54pm UTC](https://www.ruby-forum.com/t/ruby-regexp-implementation/185058 "2010-03-12T19:54:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [March 12, 2010, 7:54pm UTC](https://www.ruby-forum.com/t/ruby-regexp-implementation/185058/1 "2010-03-12T19:54:04Z")

</div>

This probably doesn’t belong in Ruby Core. I was reading this article:  
[http://swtch.com/~rsc/regexp/regexp1.html](http://swtch.com/~rsc/regexp/regexp1.html)  
[http://swtch.com/~rsc/regexp/regexp2.html](http://swtch.com/~rsc/regexp/regexp2.html)  
[http://swtch.com/~rsc/regexp/regexp3.html](http://swtch.com/~rsc/regexp/regexp3.html)

And in the first few lines of the first page, it shows that the Regexp  
implementation for Perl is absolutely terrible, and it says that Ruby is  
“the same” or at least similar. Is Ruby 1.8 / 1.9 using the Thompson NFA  
matching? Will Ruby 2.0 use it?

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [March 12, 2010, 10:05pm UTC](https://www.ruby-forum.com/t/ruby-regexp-implementation/185058/2 "2010-03-12T22:05:05Z")

</div>

On Mar 12, 2010, at 12:54 PM, Aldric G. wrote:

> This probably doesn’t belong in Ruby Core. I was reading this article:  
> [Regular Expression Matching Can Be Simple And Fast](http://swtch.com/~rsc/regexp/regexp1.html)  
> [Regular Expression Matching: the Virtual Machine Approach](http://swtch.com/~rsc/regexp/regexp2.html)  
> [Regular Expression Matching in the Wild](http://swtch.com/~rsc/regexp/regexp3.html)
> 
> And in the first few lines of the first page, it shows that the Regexp  
> implementation for Perl is absolutely terrible, and it says that Ruby is  
> “the same” or at least similar. Is Ruby 1.8 / 1.9 using the Thompson NFA  
> matching? Will Ruby 2.0 use it?

I remember reading that article when it was first published.

Ruby switched to a new regex library almost 2 years ago. Check out  
[http://rubyforge.org/projects/oniguruma](http://rubyforge.org/projects/oniguruma) for more information.

It would be interesting to see those benchmarks run again with these new  
implementations.

cr

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [March 12, 2010, 10:14pm UTC](https://www.ruby-forum.com/t/ruby-regexp-implementation/185058/3 "2010-03-12T22:14:26Z")

</div>

Aldric G. wrote:

> This probably doesn’t belong in Ruby Core. I was reading this article:  
> [Regular Expression Matching Can Be Simple And Fast](http://swtch.com/~rsc/regexp/regexp1.html)  
> [Regular Expression Matching: the Virtual Machine Approach](http://swtch.com/~rsc/regexp/regexp2.html)  
> [Regular Expression Matching in the Wild](http://swtch.com/~rsc/regexp/regexp3.html)
> 
> And in the first few lines of the first page, it shows that the Regexp  
> implementation for Perl is absolutely terrible, and it says that Ruby is  
> “the same” or at least similar. Is Ruby 1.8 / 1.9 using the Thompson NFA  
> matching? Will Ruby 2.0 use it?

def pathologicalize (str, n)  
tmp = str[0]_n  
[str_n + tmp, tmp]  
end

puts RUBY\_VERSION  
1.step(101, 10) do |n|  
full\_str, part\_str = pathologicalize(“a?”, n)  
start = Time.now  
1000.times do  
full\_str =~ /#{part\_str}/  
end  
duration = Time.now-start  
puts “#{n}:\t#{duration}”  
end

#output  
1.9.1  
1: 0.015625  
11: 0.015625  
21: 0.015625  
31: 0.03125  
41: 0.03125  
51: 0.046875  
61: 0.046875  
71: 0.046875  
81: 0.0625  
91: 0.0625  
101: 0.078125

Siep

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [March 12, 2010, 11:48pm UTC](https://www.ruby-forum.com/t/ruby-regexp-implementation/185058/4 "2010-03-12T23:48:07Z")

</div>

Hi,

In message “Re: Ruby Regexp implementation?”  
on Sat, 13 Mar 2010 03:54:09 +0900, Aldric G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|And in the first few lines of the first page, it shows that the Regexp  
|implementation for Perl is absolutely terrible, and it says that Ruby is  
|“the same” or at least similar. Is Ruby 1.8 / 1.9 using the Thompson NFA  
|matching? Will Ruby 2.0 use it?

No plan. We need more (human) resource.

```
          matz.

```
