Advertisement
cwchen

test html tags other than img

May 16th, 2015
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var testRegex = function (string) {
  2.   var pattern1 = /<[^>]+>/ig;
  3.   var pattern2 = /<img [^>]+>/ig;
  4.  
  5.   return (pattern1.test(string) && !pattern2.test(string));
  6. };
  7.  
  8. console.log(testRegex("abc<a href='http://example.com'>Link</a>defg")); // true
  9. console.log(testRegex("abc<img src='example.jpg'>defg")); // false
  10. console.log(testRegex("abc<a href='http://example.com'>Link</a>de<div>kkk</div>\
  11. fg<img src='example.jpg'>")); // false
  12. console.log(testRegex("abcdefg"));  // false
  13. console.log(testRegex("abc<img src='example.jpg'>defg<img src='example.jpg'><im\
  14. g src='example.jpg' width=25 height=25>")); // false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement