-1

I am getting the content of the body like so, document.body.innerHTML and I need to find anywhere where the word lol appears as a whole word and not as part of another word. For example:

find lol in: <p>lol</p>

find LOL in: <p>LOL </p>

find lol in: <p> lol.</p>

find lol in: <p> lol </P>

do not find lol in: <p>lolaso</p>

It is ok if the search finds lol in: <a href="http://lol.com"> as I already have a filter for that.

Manuel Medina
  • 409
  • 1
  • 7
  • 14
  • If you're going to mark this question as a duplicate, please provide the link in the question's comment to the question to the original question instead of just waiting for enough flags to close it and populate said link. Failing to do so does not help the OP until successful post locking. – kayleeFrye_onDeck Dec 11 '15 at 21:52
  • I took a look at that answer before posting mine, but we both have different questions. This question deals with how to search for a complete word within a document where the other question is trying to find a substring in the document. – Manuel Medina Dec 12 '15 at 05:20
  • Part of what makes a good question is by giving it specific wording. You need to re-word your question to be less vague/general. Your title looks more like a few words thrown together in a Google search, so don't be surprised if a flood of flags come in to shut the question down. I suggest checking the Help-Center here: http://stackoverflow.com/help/closed-questions – kayleeFrye_onDeck Dec 17 '15 at 00:01

1 Answers1

1

/\blol\b/i

i flag makes it case-insensitive.

See also: http://www.regular-expressions.info/wordboundaries.html

Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177