# Regexp issues

**URL:** <https://www.ruby-forum.com/t/regexp-issues/153761>\
**Category:** Ruby\
**Created:** [November 20, 2008, 9:04pm UTC](https://www.ruby-forum.com/t/regexp-issues/153761 "2008-11-20T21:04:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [November 20, 2008, 9:04pm UTC](https://www.ruby-forum.com/t/regexp-issues/153761/1 "2008-11-20T21:04:11Z")

</div>

[http://pastie.org/319919](http://pastie.org/319919)

On line 42, I get an error that there is no function ‘[]’ for  
nil:Nilclass… am I just missing something extremely obvious?

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [November 20, 2008, 9:12pm UTC](https://www.ruby-forum.com/t/regexp-issues/153761/2 "2008-11-20T21:12:12Z")

</div>

Alle Thursday 20 November 2008, Tim M. ha scritto:

> [http://pastie.org/319919](http://pastie.org/319919)
> 
> On line 42, I get an error that there is no function ‘[]’ for  
> nil:Nilclass… am I just missing something extremely obvious?

You get that error because Regexp#match returns nil if there’s no match.  
In  
this case, test is set to nil and, obviously, won’t have a [] method.

Stefano

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [November 20, 2008, 9:13pm UTC](https://www.ruby-forum.com/t/regexp-issues/153761/3 "2008-11-20T21:13:23Z")

</div>

Tim M. wrote:

> [http://pastie.org/319919](http://pastie.org/319919)
> 
> On line 42, I get an error that there is no function ‘[]’ for  
> nil:Nilclass… am I just missing something extremely obvious?

Your regex does not match the string, so the call to match returns nil.

HTH,  
Sebastian

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [November 20, 2008, 9:53pm UTC](https://www.ruby-forum.com/t/regexp-issues/153761/4 "2008-11-20T21:53:22Z")

</div>

Ah… hehe, thanks guys!
