RegExp to match sentences in a paragraph

A

Ana

I am trying to write a function that will take compare two paragraphs
and make the sentences that dont match ta different color. I have an
text box where the user will edit a paragraph and when I call the
function I send the original paragraph as a parameter "str" and the
user input is "re". My code (as ugly and inefficient as it may be)
seems to work for everything but the case of when a user erases a word
from the original sentence. It still finds the edited sentence in the
paragraph so it doesnt change color. I am a javascript hack so the
following code may be very sloppy.

Here is the code:
/***********************************

function trimString (str) {
str = this != window? this : str;
return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function matchMe(re, str) {
str = trimString(str);
var re_array = re.split(".");
var pattern = new Array();
for (var i=0; i<re_array.length; i++)
{
re_array = trimString(re_array);
pattern = new RegExp (re_array,'ig');
}
for (var n=0; n<(re_array.length-1); n++)
{
if(str.match(pattern[n])!= null){
document.write("<span class='bodytext_w'>");
document.write(re_array[n]+". ");
document.write("</span>");
}
else{
document.write("<span class='your_answer'>");
document.write(re_array[n]+". ");
document.write("</span>");
}
}
return false;
}

***************************************************************/
Is there another approach that I can take that will capture the
scenario where a user deltes a word from a sentence?

Any information would be greatly appreciated.

Ana
 

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

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top