From: "Iachetti Federico Martín" Date: 2012-04-10T02:40:09+09:00 Subject: Re: How to pull out specific part of a variable and set to another variable? --bcaec54fb79c323cb304bd427f55 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Here's a possible approach If there should be just one match: pry(main)> var =3D "this sentence is my variable and the important information is {inside these brackets}" =3D> "this sentence is my variable and the important information is {inside these brackets}" pry(main)> new_var =3D *var.match(/({.*})/)[1]* =3D> "{inside these brackets}" If there could be more than one match: pry(main)> new_var2 =3D *var.match(/({.*})/).captures* =3D> ["{inside these brackets}"] pry(main)> new_var has only a match, while new_var2 has an array of all the occurrencies Hope it helped Federico Mart=EDn Iachetti On Mon, Apr 9, 2012 at 14:28, Charlie B. wrote: > "this sentence is my variable and the important information is {inside > these brackets}" > --bcaec54fb79c323cb304bd427f55 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Here's a possible approach

If there should be just o= ne match:

pry(main)> var =3D "this sent= ence is my variable and the important information is {inside these brackets= }"
=3D> "this sentence is my variable and the important informati= on is {inside these brackets}"
pry(main)> new_var =3D = var.match(/({.*})/)[1]
=3D>= "{inside these brackets}"

If there could be more than one match:

pry(main)> new_var2 =3D var.match(/({.*})/).captures
=3D> ["{inside these brackets= }"]
pry(main)>=A0

new_var has only a mat= ch, while new_var2 has an array of all the occurrencies

Hope it helped

Federico Mart=EDn Iachetti=


On Mon, Apr 9, 2012 at 14:28, Charlie B.= <lists@ruby-f= orum.com> wrote:
"this sentence is my variable and the important infor= mation is {inside
these brackets}"

--bcaec54fb79c323cb304bd427f55--