JavaScript Replace content while ignoring links and html tags

I'm replacing the smiley shortcuts from my text editor with img tags, but the logic I use also sees parts of links and tags as smiley shortcuts (e.g. :/ in http://, or :p in cursor:pointer in the style attribute)

How can I ignore all the links and html tags while replacing smiley shortcuts with images?

for(var key in shortcuts){
    // Check if the editor html contains the looped shortcut
    if(content.toLowerCase().indexOf(key) != -1){
        // Escaping special characters to be able to use the shortcuts in regular expression
        var k = key.replace(/[<>*()?']/g, "\\$&");

        // Make shortcuts case insensitive
        var regex = new RegExp(k, "ig");

        //Replace shortcuts with img tags (smileys)
        tinymce.activeEditor.setContent(content.replace(regex,'<img src="images/transparent.png" class="smiley_icon '+ shortcuts[key] +'">'));
    }
}
Answer:1

Here is my angular js app with html code <html> <head> <title></title> <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <...

Here is my angular js app with html code <html> <head> <title></title> <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <...

function handleCheckBoxEvent(cb){ var index = 0; switch (cb.id){ case "cb0": index = 0; alert(cb.id); break; ...

function handleCheckBoxEvent(cb){ var index = 0; switch (cb.id){ case "cb0": index = 0; alert(cb.id); break; ...

  1. switch checkbox
  2. switch checkbox value
  3. checkboxes switch android
  4. switch checkbox php
  5. ajax switch checkbox

I have this: txtNew.Attributes.Add("onkeyup", "alert('hi');"); But when I type in the textbox - no alert comes up. I just type and type and no alert ever comes up. Why is this not working? ...

I have this: txtNew.Attributes.Add("onkeyup", "alert('hi');"); But when I type in the textbox - no alert comes up. I just type and type and no alert ever comes up. Why is this not working? ...

I have a div that contains a settings icon that is a html miscellaneous symbol <span class="settings-icon">&#9881;</span> I have a jasmine test that checks the div contents to makes ...

I have a div that contains a settings icon that is a html miscellaneous symbol <span class="settings-icon">&#9881;</span> I have a jasmine test that checks the div contents to makes ...