我已经开始学习正则表达式,但它有很多元素。它匹配什么?
$x =~s/\.?0+$//;
答案 0 :(得分:12)
它从字符串末尾删除句点和尾随零,将'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'。可能不是理想的行为。
答案 1 :(得分:6)
匹配零个或一个文字点,后跟一个或多个零,然后是字符串的结尾。
\. #A literal dot
? #Zero or one of the previous character
0+ #One or more zeros
$ #End of string
答案 2 :(得分:3)
有一个App for that!