我已经开始学习正则表达式,但它有很多元素.它匹配什么?
$x =~s/\.?0+$//;
Run Code Online (Sandbox Code Playgroud)
小智 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.
Run Code Online (Sandbox Code Playgroud)
错误?好吧,'2400'将改为'24'.可能不是理想的行为.
它匹配零个或一个文字点,后跟一个或多个零,然后是字符串的结尾.
\. #A literal dot
? #Zero or one of the previous character
0+ #One or more zeros
$ #End of string
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
139 次 |
| 最近记录: |