Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to get whole sentence that contain particular word using javascript?.for example.
i have a paragraph as below.in which i want to find the sentence that contain a word 'device'

A computer is a general purpose device that can be programmed to carry out a set of arithmetic or logical operations. Since a sequence of operations can be readily changed, the computer can solve more than one kind of problem.


then getting the result as below.

A computer is a general purpose device that can be programmed to carry out a set of arithmetic or logical operations.

Thanks......
Posted

Hello Hasbina,

Here's the idea on how to do it[^] (in C#).
And here's Javascript's Regex syntax tutorial[^] to implement it in JS.
See tutorials on How to use the RegExp object in JS[^]

Cheers,
Edo
 
Share this answer
 
v2
 
Share this answer
 
Comments
hasbina 2-Sep-13 3:33am    
sir..

how to use the code below if i use a word instead of click event?

$('p').each(function() {
$(this).html($(this).text().split(/([\.\?!])(?= )/).map(
function(v){return '<span class=sentence>'+v+'</span>'}
));
});


http://stackoverflow.com/questions/13386911/use-javascript-to-get-the-sentence-of-a-clicked-word

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900