Regex在句子结尾处应删除句号

问题描述 投票:-1回答:1

这是我的正则表达式:alert(data.data.Message.replace(/<[^>]*>/g, ' ') .replace(/\s{2,}/g, ' ')).trim();

用于剥离html标签。in this image you can see what the regex is returning. after the word 'placed' there should be a period and space but the regex is taking it out and is also adding a space at the beginning of the alert.输入:<h2>Your request has been placed.<h2>you will be notified when it is available</h2>在正则表达式后,您只剩下纯文本,因为它删除了标签。但它也正在删除该周期,并且似乎将其替换为空格?

javascript regex
1个回答
0
投票

您输入的示例HTML中的文本与输出不同,并且您输入的HTML不正确(2个打开的h2标记,1个关闭的)。我先来看一下,并验证您的内部文本正确,因为正则表达式看起来不错。

© www.soinside.com 2019 - 2024. All rights reserved.