--- title: 'js正则表达式匹配闭合标签' date: 2021-09-14 09:41:00 --- ```javascript let htmlStr = fs.readFileSync(__dirname + '/data.xml', 'utf8') htmlStr = htmlStr .replace(/</g, '<') .replace(/>/g, '>') .replace(/"/g, '"') .replace(/\n/g, '') let itemArr = [] htmlStr.replace(/<item(([\s\S])*?)<\/item>/g, (word) => { console.log(word) itemArr.push(word) return word }) ```