fork download
  1. function splitTag(str) {
  2. const tokens = [];
  3. for (let i = 0; i < str.length; i++) {
  4. if (str[i] === "<") {
  5. let tag = "";
  6. while (str[i] !== ">") {
  7. tag += str[i];
  8. i++;
  9. }
  10. tag += str[i];
  11. tokens.push(tag);
  12. } else {
  13. tokens.push(str[i]);
  14. }
  15. }
  16.  
  17. return tokens;
  18. }
  19.  
  20.  
  21. const test = "你啊后啊撒发我发<blod>你好啊啊啊啊</blod>";
  22. console.log(splitTag(test));
  23.  
Success #stdin #stdout 0.03s 17044KB
stdin
Standard input is empty
stdout
你,啊,后,啊,撒,发,我,发,<blod>,你,好,啊,啊,啊,啊,</blod>