# Basic Regex question

**URL:** <https://rubytalk.org/t/basic-regex-question/49124>\
**Category:** ruby-talk\
**Created:** [17 September 2008 01:26 UTC](https://rubytalk.org/t/basic-regex-question/49124 "2008-09-17T01:26:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greg\_Hauptmann](https://avatars.discourse-cdn.com/v4/letter/g/b9bd4f/32.png) [@Greg\_Hauptmann](https://rubytalk.org/u/Greg_Hauptmann)\
**Post date:** [17 September 2008 01:26 UTC](https://rubytalk.org/t/basic-regex-question/49124/1 "2008-09-17T01:26:15Z")

</div>

dumb question perhaps, but how do I do a Ruby based regex expression  
that takes the following as input and produces the following as  
output:

INPUT: "#{some\_string}" # or perhaps if the # needs escaping this  
should be "\#{some\_string}"  
OUTPUT: "some\_string"

i.e. what do I put in: "#{some\_string}".match("???")

thanks in advance

---

<div class="post-metadata">

**Author:** ![\_Pena\_Botp1](https://avatars.discourse-cdn.com/v4/letter/_/94ad74/32.png) [@\_Pena\_Botp1](https://rubytalk.org/u/_Pena_Botp1)\
**Post date:** [17 September 2008 01:34 UTC](https://rubytalk.org/t/basic-regex-question/49124/2 "2008-09-17T01:34:11Z")

</div>

# dumb question perhaps, but how do I do a Ruby based regex expression  
# that takes the following as input and produces the following as  
# output:  
# INPUT: "#{some\_string}" # or perhaps if the # needs escaping this  
# should be "\#{some\_string}"  
# OUTPUT: "some\_string"  
# i.e. what do I put in: "#{some\_string}".match("???")

something fr,

re=/\#\{(.\*?)\}/  
#=\> /\#\{(.\*?)\}/

s="\#{some\_string}"  
#=\> "\#{some\_string}"

s.match(re).captures  
#=\> ["some\_string"]

> **···**
>
> From: Greg Hauptmann [[mailto:greg.hauptmann.ruby@gmail.com](mailto:greg.hauptmann.ruby@gmail.com)]

---

<div class="post-metadata">

**Author:** ![Greg\_Hauptmann](https://avatars.discourse-cdn.com/v4/letter/g/b9bd4f/32.png) [@Greg\_Hauptmann](https://rubytalk.org/u/Greg_Hauptmann)\
**Post date:** [17 September 2008 02:03 UTC](https://rubytalk.org/t/basic-regex-question/49124/3 "2008-09-17T02:03:34Z")

</div>

excellent - thanks heaps

> **···**
>
> On Wed, Sep 17, 2008 at 11:34 AM, Peña, Botp \<botp@delmonte-phil.com\> wrote:
> 
> > From: Greg Hauptmann [mailto:greg.hauptmann.ruby@gmail.com]  
> > # dumb question perhaps, but how do I do a Ruby based regex expression  
> > # that takes the following as input and produces the following as  
> > # output:  
> > # INPUT: "#{some\_string}" # or perhaps if the # needs escaping this  
> > # should be "\#{some\_string}"  
> > # OUTPUT: "some\_string"  
> > # i.e. what do I put in: "#{some\_string}".match("???")
> > 
> > something fr,
> > 
> > re=/\#\{(.\*?)\}/  
> > #=\> /\#\{(.\*?)\}/
> > 
> > s="\#{some\_string}"  
> > #=\> "\#{some\_string}"
> > 
> > s.match(re).captures  
> > #=\> ["some\_string"]
