From: "Iachetti Federico Martín" Date: 2012-04-10T02:42:54+09:00 Subject: Re: How to pull out specific part of a variable and set to another variable? --bcaec54fb79c1e831604bd4289a8 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Wow ... nice one Federico Mart=EDn Iachetti 2012/4/9 Jes=FAs Gabriel y Gal=E1n > On Mon, Apr 9, 2012 at 7:28 PM, Charlie B. wrote: > > I have a variable that is a long string. The variable looks like this: > > > > "this sentence is my variable and the important information is {inside > > these brackets}" > > > > The information I need is the information inside the brackets including > > the brackets themselves, as the brackets are required for when I need t= o > > reuse this information. How do I pull out just that piece? It will > > ALWAYS be in brackets and be the only brackets in that variable. > > You can try the String#[] method and a regular expression to look for > the brackets and what's inside. For example: > > s =3D "asdl=ADkmlsdmflkm=ADflk elfm lwemf=AD le {asdf=ADsdf sdfds=ADf} as= df df " > =3D> "asdlkmlsdmflkmflk elfm lwemf le {asdfsdf sdfdsf} asdf df " > > s[/{[^}]+}=AD/] > =3D> "{asdfsdf sdfdsf}" > > Jesus. > > --bcaec54fb79c1e831604bd4289a8 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Wow ... nice one
Federico Mart=EDn Iachetti



--bcaec54fb79c1e831604bd4289a8--