0

i am trying to find tow many different texttypes are inside a innerhtml, somehow it doesn't find anything but when i test it with the same functions and a test sample it works.

    function numberoftext (a){if (a.match(/class=\"chattext\"/g)!==null){return a.match(/class=\"chattext\"/g).length;}else{return 0;}}
function numberofglobal (a){if (a.match(/class=\"chattextglobal\"/g)!==null){return a.match(/class=\"chattextglobal\"/g).length;}else{return 0;}}
function numberofclan (a){if (a.match(/class=\"chattextclan\"/g)!==null){return a.match(/class=\"chattextclan\"/g).length;}else{return 0;}}
function numberofgroup (a){if (a.match(/class=\"chattextgroup\"/g)!==null){return a.match(/class=\"chattextgroup\"/g).length;}else{return 0;}}
function numberofwisper (a){if (a.match(/class=\"chattextwhisper\"/g)!==null){return a.match(/class=\"chattextwhisper\"/g).length;}else{return 0;}}
function numberofworld (a){if (a.match(/class=\"worldsay\"/g)!==null){return a.match(/class=\"worldsay\">/g).length;}else{return 0;}}
function numberofscream (a){if (a.match(/class=\"chattextscream\"/g)!==null){return a.match(/class=\"chattextscream\"/g).length;}else{return 0;}}
var   innertextraw1 =chatupdateFrame.document.documentElement.innerHTML;
var innertextraw=    innertextraw1.substring(innertextraw1.indexOf("parent.chattextFrame.add(")+26, innertextraw1.indexOf("', 0);"));

console.log("got update",innertextraw);
console.log("t:",numberoftext(innertextraw),"c:",numberofclan(innertextraw),"w:",numberofwisper(innertextraw),"gr:",numberofgroup(innertextraw),"gl:",numberofglobal(innertextraw),"sc:",numberofscream(innertextraw));

an example for innertextraw is: "<p class=\"chattext\"><i><b>noone</b> goes with <b>someone</b> to the house</i></p>" testing it like that works fine also when i set innertextraw to the example which i got from the console log, in the website it returns just 0.

1 Answer 1

1

You don't need to escape your " quotes to match escaped quotes in a string.

a.match(/class="chattext"/g)

In a real string, those escape slashes don't actually exist, there's just no way to represent a literal double (or single) quote if the string is using that character as a delimiter, so you have to escape it.

Here's a working example:

var innerRawText = "<p class=\"chattext\"><i><b>noone</b> goes with <b>someone</b> to the house</i></p>";

var result = innerRawText.match(/class="chattext"/g);
console.log(result);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.