Question:
JavaScript full word recognized only?
Ben
2009-11-21 14:17:13 UTC
I'm using this script:
http://ottodestruct.com/itunes/explicit.txt
to recognize any bad words and mark the song as explicit. But the problem is, the script recognizes any word with a bad word WITHIN it too and marks it as explicit. For example, "hello" is explicit according to the script because it contains the word "Hell". Is there a way in JavaScript for me to make it recognize the full word only when it's alone and not when it's within another word?
Three answers:
Michael
2009-11-24 08:22:33 UTC
In your script, change the following:



/badword1|b...2|badword3/i



to:



/\b(badword1|b.2|badword3)\b/i



the "\b" in the regular expressions specifies to match on a word boundary, which is any space, punctuation, etc...
2009-11-21 14:27:47 UTC
Look for the word hell
coolanswerer
2009-11-21 14:22:36 UTC
Use a tokenizer or split the string using " " as a delimiter.



If you can't do that in JS, then make your term "hell " or " hell".



BTW: Hell isn't a bad word.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...