let name = `
<div>
<image src='aaaa'></image>
<image src='1111'></image>
<image src='222'></image>
<image src='33333'></image>
<image
src='3333'
></image>
</div>
`;
// 正则匹配标签,支持换行
console.log(name)
let uw = name.replace(/<image[^>]*?><\/image>/g, function (word) {
console.log(word)
// return word.substring(0,1).toUpperCase()+word.substring(1);
}
);
第二种案例
let name = `
<div
sss
>
<image src='aaaa'></image>
<image src='1111'></image>
<image src='222'></image>
<image src='33333'></image>
<image
src='3333'
></image>
</div>
<div></div>
`;
// 正则匹配标签,支持换行
// console.log(name)
let uw = name.replace(/<div[^>]*?>([^]*)<\/div>/g, function (word) {
console.log(word)
// return word.substring(0,1).toUpperCase()+word.substring(1);
}
);
这篇博客探讨了如何使用正则表达式来匹配和处理HTML标签,特别是在处理带有换行的复杂标签结构时。示例中展示了针对`<image>`和`<div>`标签的匹配和操作,为前端和后端开发者提供了关于字符串处理的实用技巧。
384

被折叠的 条评论
为什么被折叠?



