Regex 这个perl正则表达式与什么匹配?
我已经开始学习正则表达式,但它包含了很多元素。它和什么相配Regex 这个perl正则表达式与什么匹配?,regex,perl,Regex,Perl,我已经开始学习正则表达式,但它包含了很多元素。它和什么相配 $x =~s/\.?0+$//; 它匹配零或一个文字点,后跟一个或多个零,然后是字符串的结尾 \. #A literal dot ? #Zero or one of the previous character 0+ #One or more zeros $ #End of string 它从字符串末尾删除句点和尾随零,将“24.00”更改为“24”。分块: s/ substitute oper
$x =~s/\.?0+$//;
它匹配零或一个文字点,后跟一个或多个零,然后是字符串的结尾
\. #A literal dot
? #Zero or one of the previous character
0+ #One or more zeros
$ #End of string
它从字符串末尾删除句点和尾随零,将“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”。可能不是想要的行为。有一个错误 你的回答很有帮助。谢谢你不是“?”零个还是前面的一个字符?虽然我可能错了,但这是我从正则表达式中记得的。很好!如果正则表达式的目的是删除仅包含零的数字的小数部分,则不应将
\.
视为可选。有一个Perl模块用于此!