regex - 正则表达式 - 匹配多个不跟数值的特定字符实例
问题描述
我需要一个正则表达式查询来匹配以下内容:
hello%20world //Wont match
hello % dog //Will match
hello %20 world //Wont match
hello %% world //Will match but twice (Wont match as whole word of %%, will match single "%" and then the second "%")
我正在使用正则表达式替换任何不带数字的“%”匹配项。如果它包含“%%”,我也想用“A”替换这两个,所以我得到“AA”而不是“A”。
我的正则表达式尝试:
%[^0-9]
https://regex101.com/r/Z9N7QJ/1
问题是它的匹配,但也与下一个字符匹配,所以我的字符串“Hello % world”匹配“%”。我的“%%”被匹配为一对而不是单打。
谢谢。
解决方案
推荐阅读
- python - 传递变量时Python Selenium找不到元素
- discord - 为 cog 文件 discord.py 中的每个命令创建不同的错误处理程序
- html - 将长度转换为无单位数
- c++ - 有没有办法找到 Visual Studio 代码在内部使用的构建命令?
- unit-testing - 如何用 val 模拟()类
- node.js - 获取压缩文件夹的文件路径 cross-zip
- java - 寻路 A* 算法显示问题
- java - Action Listener 绘制程序:如何实现绘制点、三角形、多边形、撤消按钮、厚度和填充?
- javascript - NodeJs:无法发送带有正文参数的 POST 请求:在服务器上时未定义 req.body.param
- re - 反VMware?检查主函数的参数 == 2 或 1?