gpt4 book ai didi

regex - 这个 perl 正则表达式匹配什么?

转载 作者:行者123 更新时间:2023-12-01 06:59:34 24 4
gpt4 key购买 nike

我已经开始学习正则表达式,但这其中有很多元素。它匹配什么?

$x =~s/\.?0+$//;

最佳答案

它从字符串的末尾删除句点和尾随零,将 '24.00' 更改为 '24'。分片:

s/  substitute operation
\. literal period, not a placeholder
? Period is optional (by the way, probably a bug)
0+ one or more zeros
$ all of this at the end of the string.
// replace it with nothing, i.e., just delete it.

错误?好吧,“2400”将更改为“24”。可能不是想要的行为。

关于regex - 这个 perl 正则表达式匹配什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7536823/

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