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
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 thisYou 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 characterJesus.
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs