简体   繁体   中英

Javascript regex: replace url text link with image,but not in html tags

Hi this is my pice of code:

                    <div style="overflow: hidden; width: 445px;">[IMG]http://i29.tinypic.com/mydog.png[/IMG] tak si to http://i29.tinypic.com/mycat.png  Lorem ipsum loremai <img width="15" border="0" align="middle" src="images/smejo.gif" valign="middle"/> <img src=http://www.example.com/index.png alt> <img src="http://www.example.com/index.png" alt>     <a href="#reakcia" title="reagovat na temu"><span class="poradna-tl-reaguj"><reaction> </span></a></div>
        </td>           </tr><img src=http://www.example.com/index.png alt><img src="http://www.example.com/index.png" alt>

and i need regex pattern to replace ONLY text image links with image without touch of inner url tags. But i can't use " Lookbehind " or possessive quantifiers because JS don't support them=/ So i want to catch only " http://i29.tinypic.com/mydog.png " and " http://i29.tinypic.com/mycat.png ".

I using array method to replacing (will be greasemonkey script.) Many Thanks

...whole day i cant solved this and now after few minutes...

Answer

((?:(?:https?|ftp|file)://|www\.|ftp\.)[-A-Z0-9+&@#/%=~_|$?!:,.]*[A-Z0-9+&@#/%=~_|$]+.(jpg|png|gif|jpeg|bmp))(?!([^<]+)?>)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM