# What does this regexp do?

**URL:** <https://www.ruby-forum.com/t/what-does-this-regexp-do/150018>\
**Category:** Ruby\
**Created:** [October 2, 2008, 4:13pm UTC](https://www.ruby-forum.com/t/what-does-this-regexp-do/150018 "2008-10-02T16:13:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_DeLorme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9d8465/32.png) [@Daniel\_DeLorme](https://www.ruby-forum.com/u/Daniel_DeLorme)\
**Post date:** [October 2, 2008, 4:13pm UTC](https://www.ruby-forum.com/t/what-does-this-regexp-do/150018/1 "2008-10-02T16:13:46Z")

</div>

I can’t figure out what this does:

> > “1\n2\n3\n”[/.\Z?/]  
> > =\> “”

I would expect it to output “1”, just as:

> > “1\n2\n3\n”[/.(\Z)?/]  
> > =\> “1”

Is this a bug?

---

<div class="post-metadata">

**Author:** ![Daniel\_DeLorme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9d8465/32.png) [@Daniel\_DeLorme](https://www.ruby-forum.com/u/Daniel_DeLorme)\
**Post date:** [October 2, 2008, 4:51pm UTC](https://www.ruby-forum.com/t/what-does-this-regexp-do/150018/2 "2008-10-02T16:51:21Z")

</div>

On Oct 2, 10:11 am, Daniel DeLorme [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I can’t figure out what this does:
> 
> > > “1\n2\n3\n”[/.\Z?/]  
> > > =\> “”
> 
> I would expect it to output “1”, just as:
> 
> > > “1\n2\n3\n”[/.(\Z)?/]  
> > > =\> “1”
> 
> Is this a bug?

Neither one of those make any sense. An optional end-of-string means  
nothing. That second one is the same as [/./]

– Mark.
