javascript - 如何
从字符串中删除所有标签
问题描述
我有一个大字符串
Hello<br>I am a On then sake home is am leaf<br> Of suspicion do departure at extremely he
believing.<br> Do know said mind do rent they oh hope of <br> General enquire picture letters garrets on
offices of no on<br> Say one hearing between excited evening all inhabit thought you<br> Style begin mr
heard by in music tried do<br> To unreserved projection no introduced invitation<br> .... 1200 words.
现在我想<br>
用“”替换这些标签。我不知道正则表达式,有人可以帮我吗?而且我使用了javascript字符串替换,但它没有用。
解决方案
替换<br>
为常规空间" "
。
const yourString = "Hello<br>I am a On then sake home is am leaf<br> Of suspicion do departure at extremely he believing.<br> Do know said mind do rent they oh hope of <br> General enquire picture letters garrets on offices of no on<br> Say one hearing between excited evening all inhabit thought you<br> Style begin mr heard by in music tried do<br> To unreserved projection no introduced invitation<br>"
const result = yourString
.replace(/<br>/gi," ") // REPLACES ALL <br> OCCURRENCES FOR A REGULAR SPACE
.replace(/\s+/g," ") // REPLACES POSSIBLE MULTIPLE SPACES FOR A SINGLE SPACE
.trim(); // REMOVES POSSIBLE SPACES FROM THE BEGINNING AND END OF THE STRING
console.log(result);
更换<br>
常规新线路"\n"
。
const yourString = "Hello<br>I am a On then sake home is am leaf<br> Of suspicion do departure at extremely he believing.<br> Do know said mind do rent they oh hope of <br> General enquire picture letters garrets on offices of no on<br> Say one hearing between excited evening all inhabit thought you<br> Style begin mr heard by in music tried do<br> To unreserved projection no introduced invitation<br>"
const result = yourString
.replace(/<br>\s*/gi,"\n") // REPLACES ALL <br> FOLLOWED BY 0 OR MORE SAPCES FOR A NEW LINE
.trim(); // REMOVES POSSIBLE SPACES FROM THE BEGINNING AND END OF THE STRING
console.log(result);
推荐阅读
- .net - 来自 OnTeamsMessagingExtensionSubmitActionAsync 的用户状态(.Net Core、Botframework、Microsoft Teams)
- javascript - 如何在 React 应用程序中实现谷歌地图搜索框
- android - 从 Firebase 实时数据库中读取参考 = 用户 UID
- java - Apache骆驼如何以“正文”格式提交正文
- python - 如何使用 pygame 在屏幕上调整帧速率?
- java - “Binary XML file line #47: Binary XML file line #47: Error inflating class EditText” 是什么意思?
- flutter - 无法从方法返回类型值,因为它的返回类型为
- c++ - 在自定义目标运行后重建依赖目标
- javascript - React,映射到一个中等复杂的 json 对象以获取消息中的键
- python - 在 pyplot 中使用随机数据和位置创建颜色图