【问题标题】:JavaScript/regex: Remove text between brackets in string [duplicate]JavaScript / regex:删除字符串中括号之间的文本[重复]
【发布时间】:2020-07-04 07:57:48
【问题描述】:

如何从字符串中删除所有 标签以及其中的内容?

<p>Hello, how are you doing <strong>today</strong></p>

到

Hello, how are you doing today

在正则表达式中使用 JavaScript?

【问题讨论】:

  • "<p>Hello, how are you doing <strong>today</strong></p>".replace(/\<[^>]+\>/g, '')

标签: javascript regex string


【解决方案1】:

你可以这样做:

const input = '<p>Hello, how are you doing <strong>today</strong></p>';

const result = input.replace(/<[^>]+>/g, '');

console.log(result);

【讨论】:

  • 太棒了!谢谢。抱歉,Regex 真的让我对所有挤在一起的随机符号感到困惑。
  • 我建议你使用regex101.com 来解释和帮助调试正则表达式
猜你喜欢
  • 2021-12-02
  • 1970-01-01
  • 1970-01-01
  • 2020-04-08
  • 1970-01-01
  • 2019-11-14
  • 2015-10-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多