# Regex noob question

**URL:** <https://www.ruby-forum.com/t/regex-noob-question/143093>\
**Category:** Rails\
**Created:** [July 15, 2008, 6:30am UTC](https://www.ruby-forum.com/t/regex-noob-question/143093 "2008-07-15T06:30:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gsterndale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@gsterndale](https://www.ruby-forum.com/u/gsterndale)\
**Post date:** [July 15, 2008, 6:30am UTC](https://www.ruby-forum.com/t/regex-noob-question/143093/1 "2008-07-15T06:30:36Z")

</div>

Using a regular expression, how would I match “howdy” in the  
following?

“begin howdy end begin hello end” =~ /begin (.\*) end/

match = $1

# current value of match = “howdy end begin hello”

A handy regex tool: [http://www.rubular.com](http://www.rubular.com)

---

<div class="post-metadata">

**Author:** ![gsterndale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@gsterndale](https://www.ruby-forum.com/u/gsterndale)\
**Post date:** [July 15, 2008, 8:16am UTC](https://www.ruby-forum.com/t/regex-noob-question/143093/2 "2008-07-15T08:16:33Z")

</div>

On Jul 14, 2008, at 9:29 PM, gsterndale wrote:

> Using a regular expression, how would I match “howdy” in the  
> following?
> 
> “begin howdy end begin hello end” =~ /begin (.\*) end/
> 
> match = $1
> 
> # current value of match = “howdy end begin hello”

Assuming it’s that exact string…

> > “begin howdy end begin hello end” =~ /begin (.\*?) /; $1  
> > =\> “howdy”

But I suspect that won’t work for your real usage…

---

<div class="post-metadata">

**Author:** ![gsterndale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@gsterndale](https://www.ruby-forum.com/u/gsterndale)\
**Post date:** [July 15, 2008, 9:42am UTC](https://www.ruby-forum.com/t/regex-noob-question/143093/3 "2008-07-15T09:42:52Z")

</div>

You’re right. Unfortunately, that won’t work for me. However, the  
following will!

> > “begin hi there end begin hello end” =~ /begin (.\*?) end/; $1  
> > =\> “hi there”

Thanks Philip
