Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 这个perl正则表达式与什么匹配?_Regex_Perl - Fatal编程技术网

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模块用于此!