Advertisement
emotrend

html strict mode

Feb 11th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. function solve(input) {
  2.  
  3. let basicBasicPattern = /^<(\w+)>.*<\/\1>$/g;
  4. let wordPattern = />(.*?)</g;
  5.  
  6. let resultStr = [];
  7. for (let el of input) {
  8. let wordMatch = el.match(basicBasicPattern);
  9. if (wordMatch === null) {
  10. continue;
  11. } else {
  12. let secondMatch = wordMatch[0].match(wordPattern);
  13. secondMatch.forEach(el => {
  14. if (el !== '><') {
  15. let currEl = el.slice(1, el.length - 1).trim();
  16. currEl = currEl.split('');
  17. resultStr.push(currEl.join(''));
  18. }
  19. });
  20. }
  21. }
  22. console.log(resultStr.join(' '));
  23. }
  24.  
  25. solve(['<div><p>This</p> is</div>',
  26. '<div><a>perfectly</a></div>',
  27. '<divs><p>valid</p></divs>',
  28. '<div><p>This</div></p>',
  29. '<div><p>is not</p><div>'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement