javascript - 如何使用正则表达式匹配除加号之外的所有非数字字符?
问题描述
如何使用正则表达式匹配任何不是 0-9 和 + 的字符?我希望能够匹配除数字和加号以外的所有字符。
/\D+/ 匹配所有不是数字的字符,但我希望它对于数字和 + 为假
解决方案
使用[^0-9+]+
模式,根据regex101 示例:
[^0-9+]+
Match a single character not present in the list below [^0-9+]+
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
+ matches the character + literally (case sensitive)
推荐阅读
- c# - 如何将父级转换为子级以在 C# 中调用正确的函数
- c# - C# - 函数跳过“if”循环
- kentico - 如何在首次使用时重置自动生成的 Kentico 密码?
- javascript - Formik,子组件中的useField()?
- uwp - 错误 APPX1204:无法签署 UWP 项目
- docker - 如何在启用 GUI 的情况下重新启动 ROS docker 容器
- pyspark - AWS 胶水 pyspark - 将源表中的一行转换为目标中的多行
- postgresql - 如何将两个小时添加到时间戳值,然后将其重新转换为仅包含小时和分钟的字符串?
- r - R:计算百分比相对频率并将它们应用于所有列的构建函数
- html - Accordion(仅限 html 和 css)适用于 Chrome,但不适用于 Edge 和 Mozilla