如何使用正则表达式获取 table 中一行的第一个数字?

How can I get the first number of a line in this table with regex?

GitLab 提供了一个选项,让徽章代表您当前的代码覆盖率。它通过查看一些 CI 脚本的输出,然后在输出上运行正则表达式来做到这一点。

话虽如此,给定这样的输出:

-------------------|----------|----------|----------|----------|----------------|
File               |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
-------------------|----------|----------|----------|----------|----------------|
All files          |      100 |       50 |      100 |      100 |                |
 actions/flight    |      100 |      100 |      100 |      100 |                |
  filter.js        |      100 |      100 |      100 |      100 |                |
 components/Button |      100 |       50 |      100 |      100 |                |
  Button.jsx       |      100 |       50 |      100 |      100 |                |
 components/Toggle |      100 |      100 |      100 |      100 |                |
  Toggle.jsx       |      100 |      100 |      100 |      100 |                |
-------------------|----------|----------|----------|----------|----------------|

我希望能够得到 All files:% Stmts 的值(在本例中应该是 100)。

目前我正在使用这个正则表达式,但它似乎无法解决问题:

/^All files\s*\|\s*(\d*)/

我在配置我们的 GitLab 实例以使用 Jest 报告代码覆盖率时遇到了同样的问题。它似乎在全局模式下工作,所以多行解决方案确实行不通,就像@4castle 所建议的那样。

我们最终使用的正则表达式如下,它也匹配浮点数:

/All files\s*\|\s*([\d.]+)/