Krupski
09-20-2011, 12:59 AM
Hi all,
I have a string which contains HTML and *possibly* IMG tags. I am trying to extract part of each IMG tag which may be in the string. The string is part of a chat-box message which may or may not contain smilies.
Here is a typical line of text, without processing (note I mis-spell the bbcode "quote" so as not to fool this board):
<img src="./images/smilies/smile.gif" alt=":smile:" title="smile" /> <img src="./images/smilies/thumbsup.gif" alt=":thumbsup:" title="thumbsup" /> <img src="./images/smilies/thumbsdown.gif" alt=":thumbsdown:" title="thumbsdown" />
Notice that each image has an "ALT" attribute which contains the smiley code of the smiley image. THAT is what I want to extract.
This is the regex I am using to grab each smiley code:
txt = txt.replace(/<img(?:.*?):(.*?):(?:.*?)\/>/gi,':$1:');
The weird thing is, the regex grabs the FIRST and LAST of the three, but not the middle one!
I'm sure the stupid mistake is sitting right in front of my face, but I'm not seeing it.
Any help will be greatly appreciated!
Thanks.
-- Roger
I have a string which contains HTML and *possibly* IMG tags. I am trying to extract part of each IMG tag which may be in the string. The string is part of a chat-box message which may or may not contain smilies.
Here is a typical line of text, without processing (note I mis-spell the bbcode "quote" so as not to fool this board):
<img src="./images/smilies/smile.gif" alt=":smile:" title="smile" /> <img src="./images/smilies/thumbsup.gif" alt=":thumbsup:" title="thumbsup" /> <img src="./images/smilies/thumbsdown.gif" alt=":thumbsdown:" title="thumbsdown" />
Notice that each image has an "ALT" attribute which contains the smiley code of the smiley image. THAT is what I want to extract.
This is the regex I am using to grab each smiley code:
txt = txt.replace(/<img(?:.*?):(.*?):(?:.*?)\/>/gi,':$1:');
The weird thing is, the regex grabs the FIRST and LAST of the three, but not the middle one!
I'm sure the stupid mistake is sitting right in front of my face, but I'm not seeing it.
Any help will be greatly appreciated!
Thanks.
-- Roger