首页 > 解决方案 > 正则表达式 - 删除字符串后面和之前的空格

问题描述

我正在寻找一个 json 正则表达式,它删除了 ** 后面和 ** 之前的空格以用于降价文档:示例:

This is the text that is in the source document ** text should be in bold ** more text

结果应该是:

This is the text that is in the source document **text should be in bold** more text

我的尝试:

[ ].[**][ ]

火柴

用。。。来代替

**

这导致:

This is the text that is in the source document**text should be in bold**more text

所以不完美,谁能帮我微调这个表达式?

标签: regex

解决方案


向 Wiktor 致敬: (?<!\S)\*{2}\s*(.*?)\s*\*{2}(?!\S)并替换为**$1**


推荐阅读