fork download
  1. var console = {};
  2. console.log = function(x) {
  3. print(x);
  4. }
  5.  
  6.  
  7. function doMatch(str1) {
  8. var regex1 = /<[^<>]*>/g;
  9. var array1;
  10. var nextPos = 0;
  11. var ret = [];
  12.  
  13. while ((array1 = regex1.exec(str1)) !== null) {
  14. var matchStart = regex1.lastIndex - array1[0].length;
  15. if (nextPos < matchStart) {
  16. ret.push(str1.slice(nextPos, matchStart));
  17. }
  18. ret.push(array1[0]);
  19. nextPos = regex1.lastIndex;
  20. }
  21.  
  22. if (nextPos < str1.length - 1) {
  23. ret.push(str1.slice(nextPos));
  24. }
  25.  
  26. return ret;
  27. }
  28.  
  29. console.log(doMatch('abc<def>hij</klm>nop<qrs>tuv</wxy>z'));
  30. console.log(doMatch('<def>hij</klm>nop<qrs></wxy>'));
Success #stdin #stdout 0.29s 39148KB
stdin
Standard input is empty
stdout
abc,<def>,hij,</klm>,nop,<qrs>,tuv,</wxy>
<def>,hij,</klm>,nop,<qrs>,</wxy>