From: Rajkumar Surabhi on 12 Mar 2010 05:48 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 -- Posted via http://www.ruby-forum.com/.
From: Jesús Gabriel y Galán on 12 Mar 2010 05:52 On Fri, Mar 12, 2010 at 11:48 AM, Rajkumar Surabhi <mailtorajuit(a)gmail.com> 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 = "i am testing the app" => "i am testing the app" irb(main):004:0> s[/\btest\w*/] => "testing" \b --> word boundary \w --> word character Jesus.
From: Jean G. on 12 Mar 2010 07:09 On Fri, Mar 12, 2010 at 6:48 PM, Rajkumar Surabhi <mailtorajuit(a)gmail.com> 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 > or use scan: irb(main):005:0> s="iam testung the aplication" => "iam testung the aplication" irb(main):006:0> s.scan /\btest\w*/ => ["testung"]
From: Rajkumar Surabhi on 12 Mar 2010 07:23 thanxs how to get the first word matches the expresion if i have no of words which matches. Jesús Gabriel y Galán wrote: > On Fri, Mar 12, 2010 at 11:48 AM, Rajkumar Surabhi > <mailtorajuit(a)gmail.com> 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 = "i am testing the app" > => "i am testing the app" > irb(main):004:0> s[/\btest\w*/] > => "testing" > > \b --> word boundary > \w --> word character > > Jesus. -- Posted via http://www.ruby-forum.com/.
From: Rolf Pedersen on 12 Mar 2010 08:01 If I understand you correctly, this'll do the trick: irb(main):024:0* s="Iam testung the aplication" => "Iam testung the aplication" irb(main):025:0> s[/\btest\w*/]||s[/\w*/] => "testung" irb(main):026:0> s="Iam running the aplication" => "Iam running the aplication" irb(main):027:0> s[/\btest\w*/]||s[/\w*/] => "Iam" -Rolf On Fri, Mar 12, 2010 at 1:23 PM, Rajkumar Surabhi <mailtorajuit(a)gmail.com>wrote: > > thanxs > how to get the first word matches the expresion if i have no of words > which matches. > > Jesús Gabriel y Galán wrote: > > On Fri, Mar 12, 2010 at 11:48 AM, Rajkumar Surabhi > > <mailtorajuit(a)gmail.com> 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 = "i am testing the app" > > => "i am testing the app" > > irb(main):004:0> s[/\btest\w*/] > > => "testing" > > > > \b --> word boundary > > \w --> word character > > > > Jesus. > > -- > Posted via http://www.ruby-forum.com/. > >
|
Pages: 1 Prev: Beware prelink and compiling ruby from source Next: how to check the file field empty |