Advertisement
Guest User

golfing on html parsing with regex

a guest
Jul 22nd, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var test_string_html = '<strong><i>more</i> <span style="color: red">complicated</span></strong>';
  2. var count = 7;
  3.  
  4. test_string_html_2 = test_string_html.split(/<.*?>/gi);
  5. test_string_html_3 = test_string_html.split(/>.*?(?=<)/gi);
  6. test_string_html_4 = test_string_html_2.join("").slice(0,count);
  7. var test_string_html_5 = "";
  8.  
  9. for( i = 0; i < test_string_html_3.length; i++){
  10.     test_string_html_5 += test_string_html_2[i] + test_string_html_3[i] + ">";
  11. }
  12.  
  13. console.log(test_string_html);
  14. console.log(test_string_html_2);
  15. console.log(test_string_html_3);
  16. console.log(test_string_html_4);
  17. console.log(test_string_html_2.length);
  18. console.log(test_string_html);
  19. console.log(test_string_html_5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement