I'm trying to remove all non-alphanumeric characters from a string and then proceed to count the amount of words for each line extracted from a pdf.
var m = item["str"].replace(/[^a-zA-Z0-9 ]/g," ").trim().split(" ");
console.log("count: " + m.length + " words: " + m);
This is the code. An example of the resulting output:
count: 10 words: The,Quick,Brown,Fox,,,Jumps,Over,The,Lazy
While item["str"] looks like this:
The Quick Brown Fox - Jumps Over The Lazy
Some output also looks like this:
count:1 words:
Can anyone help me understand what's going on here? Thank in advance!