regex - Regex to catch comma-separated decimal numbers not inside latex command
问题描述
I am trying to create a regex to catch comma-separated decimal numbers not inside LaTeX command \num{}
.
Here are examples of what I want to catch:
2,47
12,67
\mathbf{12,76}
Here are examples that I don't want to catch:
\num{2,76}
\num{12,76}
I tried this regex but it doesn't work.
(?<!num\{)(\d*\,\d*)
Thanks!
解决方案
You could prepend the pattern with a word boundary and if you want to exclude multiple patterns, you could add another lookbehind.
Note that you don't have to escapte the {
and the ,
and using \d*
matches 0 or more digits.
\b(?<!num{)(?<!SI{)\d+,\d+
See a regex demo
推荐阅读
- javascript - Yodlee Fastlink iFrame 在移动网络的新标签页中打开 Yodlee UI
- ios - 无法在 Swift 包中呈现 UIViewController 及其情节提要
- android - Flutter 对未来有好处,还是 kotlin 是最好的,什么最适合移动开发?
- python-3.x - 在 Kubernetes cron 作业中运行的应用程序未连接到同一 Kubernetes 集群中的数据库
- python - Python正则表达式纠正数字格式
- sqlite - 如何从一个表中选择另一个表中不存在某个字段的条目
- python - 如何在 Google App Engine 中调试 gunicorn 和 python?
- ruby-on-rails - LoadError:无法加载“听”gem(Rails 6)
- python - 如何在 python 中从头开始编写 Simplex 方法(以表格/矩阵形式)?
- javascript - D3 contourDensity - 投影问题