Extract Words which are in Single Quotes in a 2000 Word Paragraph

J

johnvisual

I have a long paragraph which contains almost 2000 words.

I want to extract all those words or group of words which are in
single quote e.g.

In the below sentence, I want to extract 1. is 2. important and 3.
topic

This 'is' very 'important' 'topic' to discuss

Any body have any idea how to do this in javascript.
 
S

Stevo

I have a long paragraph which contains almost 2000 words.

I want to extract all those words or group of words which are in
single quote e.g.

In the below sentence, I want to extract 1. is 2. important and 3.
topic

This 'is' very 'important' 'topic' to discuss

Any body have any idea how to do this in javascript.

What about contractions like don't. They could add some trickyness to it.
 
S

SAM

Le 5/4/09 10:15 PM, (e-mail address removed) a écrit :
I have a long paragraph which contains almost 2000 words.

I want to extract all those words or group of words which are in
single quote e.g.

In the below sentence, I want to extract 1. is 2. important and 3.
topic

This 'is' very 'important' 'topic' to discuss

Any body have any idea how to do this in javascript.


Would you want also 1 and 2 here :

This 'very' good and 'very' long.

Would your "paragraph" be between 2 tags and without no other ones
inside this paragraph ?

function count() {
var t = document.getElementById('myParagraph').innerHTML;
var words = t.match(/(?:')[a-z]+(?=')/gi);
words.sort();
t = [];
for(var i=0, n=words.length; n>i; i++)
if(words!=words[i+1]) t.push(words.replace("'",""));
alert(words); // all gotten
alert(t); // without doublons
}
 
R

RobG

I have a long paragraph which contains almost 2000 words.

I want to extract all those words or group of words which are in
single quote e.g.

In the below sentence, I want to extract 1. is 2. important and 3.
topic

This 'is' very 'important' 'topic' to discuss

Any body have any idea how to do this in javascript.

Use a regular expression, here's a starting point but it may not be
exactly what you want:

var s = "I am 'some' text 'with' some words 'quoted'." +
" Don't include hyphenated words";

// Shows 'some','with','quoted'
alert(s.match(/'\w+'/g));


You may want to consider other quote characters to delimit the words
and extra characters to consider as part of a word, e.g. hyphen.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top