[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

basic Regex question

Greg Hauptmann

9/17/2008 1:26:00 AM

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

2 Answers

Peña, Botp

9/17/2008 1:34:00 AM

0

From: Greg Hauptmann [mailto:greg.hauptmann.ruby@gmail.com]=20
# 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=3D/\#\{(.*?)\}/
#=3D> /\#\{(.*?)\}/

s=3D"\#{some_string}"
#=3D> "\#{some_string}"

s.match(re).captures
#=3D> ["some_string"]

Greg Hauptmann

9/17/2008 2:04:00 AM

0

excellent - thanks heaps

On Wed, Sep 17, 2008 at 11:34 AM, Pe=F1a, Botp <botp@delmonte-phil.com> wro=
te:
> 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=3D/\#\{(.*?)\}/
> #=3D> /\#\{(.*?)\}/
>
> s=3D"\#{some_string}"
> #=3D> "\#{some_string}"
>
> s.match(re).captures
> #=3D> ["some_string"]
>
>