How to get word from sentence

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

On Fri, Mar 12, 2010 at 11:48 AM, Rajkumar S.
[email protected] 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.

On Fri, Mar 12, 2010 at 6:48 PM, Rajkumar S.
[email protected] 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”]

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 S.
[email protected] 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.

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