javascript - Help write regex that will surround certain text with <strong> tags, only if the <strong> tag isn't present -


I have many posts on the website; All these posts are such chat conversations:

Eddie: Hey!
BC: What's happening?
AD: Nothing: BC: OK

& lt; P & gt; The tag is marked as simple paragraph surrounded by.

By changing the JavaScript function, I want all the examples of "AD" in the beginning of a conversation (i.e., to be worn by & lt; strong & gt; tag All instances of "eddie" begin after one line after an ":", but only if the example is already gt; tag.

I The code I am using is like this:

  var posts = document.getElementsByClassName ('entry-content'); (Var i = 0; i & lt; posts.length ; I ++) {posts [i] .innerHTML = post [i] .winnerHTML.replace (/ here some regex / 'place of content here');}  
< P>

If AD: is always at the beginning of the line

 . (/ ^ AD: / GM, using the & lt; strong & gt; AD: & lt;  m  switch, the following regex should work. / Strong> ");   

You do not need to check the existence of because ^ from the beginning of the line And Reggae will only get if the sequence of letters is followed by the beginning of the line AD: .

You do not use "regex" as "HTML" because you HTML is not parsing, you are just changing one string with another string.

One option of Rizax will be to work Generate a range that selects the text, and then use the text bold though, I think it would be more difficult and you have to face the difference in browser implementation. Reggae method should be sufficient


your comment After watching, the following regex will work fine:

  .replace (/ & lt; (p | br)> ed: / gm,  E: & lt; / strong & gt; ");  

Comments