From: Rolf Pedersen Date: 2010-03-12T22:01:33+09:00 Subject: Re: how to get word from sentence --001485e8e7393f222804819a2108 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable If I understand you correctly, this'll do the trick: irb(main):024:0* s=3D"Iam testung the aplication" =3D> "Iam testung the aplication" irb(main):025:0> s[/\btest\w*/]||s[/\w*/] =3D> "testung" irb(main):026:0> s=3D"Iam running the aplication" =3D> "Iam running the aplication" irb(main):027:0> s[/\btest\w*/]||s[/\w*/] =3D> "Iam" -Rolf On Fri, Mar 12, 2010 at 1:23 PM, Rajkumar Surabhi w= rote: > > thanxs > how to get the first word matches the expresion if i have no of words > which matches. > > Jes=FAs Gabriel y Gal=E1n wrote: > > On Fri, Mar 12, 2010 at 11:48 AM, Rajkumar Surabhi > > wrote: > >> Hi all, > >> In my application i have to get the word which contains given word. > >> example > >> sentence: iam testung the aplication > >> i want to extract the word which starts with test > >> how to do this > > > > You can do it with a regular expression. Here is an example: > > > > irb(main):001:0> s =3D "i am testing the app" > > =3D> "i am testing the app" > > irb(main):004:0> s[/\btest\w*/] > > =3D> "testing" > > > > \b --> word boundary > > \w --> word character > > > > Jesus. > > -- > Posted via http://www.ruby-forum.com/. > > --001485e8e7393f222804819a2108--