gpt4 book ai didi

ruby - 从 ruby​​ 字符串中解析重复的匹配项?

转载 作者:数据小太阳 更新时间:2023-10-29 07:24:15 27 4
gpt4 key购买 nike

也许我只是太累了,但我没有看到像这样从字符串中解析出数字的明显方法:

some text here, and then 725.010, 725.045, 725.340 and 725.370; and more text

我想到了一件事:用空格将其拆分成一个数组。然后对数组中的每个元素应用带有组的正则表达式测试。

有没有更干净、更简单的方法来做到这一点?

最佳答案

你需要String#scan :

your_string.scan(/\d\d\d\.\d\d\d/)

将输出匹配数组。

关于ruby - 从 ruby​​ 字符串中解析重复的匹配项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4416509/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com