Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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
Python Perl正则表达式的含义_Python_Regex_Perl - Fatal编程技术网

Python Perl正则表达式的含义

Python Perl正则表达式的含义,python,regex,perl,Python,Regex,Perl,我正在使用正则表达式编写一个python脚本,我找到了perl中需要的内容,但由于我对perl不太在行,所以我不清楚编写了什么。代码如下: '\\b' . $2 .'\\b.{0,15}' . $3 . '[^\\d]{0,5}' . $4 . ((defined $5) ? '[^\\d]{0,5}' . $5 : '' 问题主要出现在of行中,它检查是否定义了$5。你能帮我理解这句话吗?那是: 将返回“[^\\d]{0,5}”$5如果定义了$5,则为空字符串。即: 将返回“[^\\d]{0

我正在使用正则表达式编写一个python脚本,我找到了perl中需要的内容,但由于我对perl不太在行,所以我不清楚编写了什么。代码如下:

'\\b' . $2 .'\\b.{0,15}' . $3 . '[^\\d]{0,5}' . $4 . ((defined $5) ? '[^\\d]{0,5}' . $5 : ''
问题主要出现在of行中,它检查是否定义了$5。你能帮我理解这句话吗?

那是:

将返回
“[^\\d]{0,5}”$5
如果定义了
$5
,则为空字符串。

即:


将返回
“[^\\d]{0,5}”$5
如果定义了
$5
,则为空字符串,否则为空。

三元(?:)表达式的括号不匹配
(defined $5) ? '[^\\d]{0,5}' . $5 : ''
^^^^^^^^^^^^   ^^^^^^^^^^^^^^^^^^   ^^
 condition      take this if true   take this if false