regex - 正则表达式 - 删除字符串后面和之前的空格
问题描述
我正在寻找一个 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
所以不完美,谁能帮我微调这个表达式?
解决方案
向 Wiktor 致敬:
(?<!\S)\*{2}\s*(.*?)\s*\*{2}(?!\S)
并替换为**$1**
推荐阅读
- erlang - 如何在 Erlang 中找到 utf8 编码二进制文件的字符长度?
- json - 我一直在尝试将 API 用于我一直在制作的股票网站,我的 api 有多个单词,它们之间有空格
- python - 给时间按下电报机器人中的 InlineKeyboardButton 按钮
- typescript - 如何在新标签中打开并使用 Cypres 切换到该标签?
- python - 在数据文件中的特定列上使用熊猫“.value_counts”
- python - 如何通过具有浮点值的“1”矩阵将其转换为“20000”?
- jinja2 - 如何将选择字段中的 form.data 作为烧瓶中的参数
- python - Python 错误:aiogram.dispatcher.dispatcher:获取更新时导致异常
- javascript - 如何禁用 div 内特定元素的悬停效果?
- c# - 避免过多的 if 语句