Advertisement
DNNdrago

03. Extract Hyperlinks

Jul 30th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (input) {
  2.     str = '';
  3.     for (var index in input) {
  4.         str += input[index];
  5.     }
  6.  
  7.     str = str.replace(/\s/g,'');
  8.  
  9.     var anchors = str.match(/<a[^>]+>/g);
  10.  
  11.     var hrefs = [];
  12.  
  13.     for(var index in anchors) {
  14.         if(anchors[index].match(/href\s*=\s*"[^"]+"/g)) {
  15.             hrefs.push(anchors[index].match(/href\s*=\s*"[^"]+"/g).toString());
  16.         }
  17.         if(anchors[index].match(/href\s*=\s*'[^']+'/g)) {
  18.             hrefs.push(anchors[index].match(/href\s*=\s*'[^']+'/g).toString());
  19.         }
  20.     }
  21.  
  22.  
  23.     for(var index in hrefs) {
  24.         if(hrefs[index].match(/="[^"]+"/g)) {
  25.             console.log(hrefs[index].match(/="[^"]+"/g).toString().replace(/(=")|"/g, ''));
  26.         }
  27.         if(hrefs[index].match(/='[^']+'/g)) {
  28.             console.log(hrefs[index].match(/='[^']+'/g).toString().replace(/(=')|'/g, ''));
  29.         }
  30.     }
  31.  
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement