Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.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
perl regexp最小匹配下划线之前的单词_Regex_Perl - Fatal编程技术网

perl regexp最小匹配下划线之前的单词

perl regexp最小匹配下划线之前的单词,regex,perl,Regex,Perl,我可以知道如何为这个案例编写regexp吗 $aword = abc_def_ghi regexp substitute to abc_def_xxx $bword = jkl_mno_pqr regexp substitute to jkl_mno_xxx $cword = abc_def regexp substitute to abc_xxx Zh 在仅由字母a到z的两个或多个“单词”组成的字符串中,将最后一个“单词”替换为xxx 您可以在中阅读有关正则表达式的内容 如果你告诉我

我可以知道如何为这个案例编写regexp吗

$aword = abc_def_ghi regexp substitute to abc_def_xxx
$bword = jkl_mno_pqr regexp substitute to jkl_mno_xxx
$cword = abc_def     regexp substitute to abc_xxx
Zh

在仅由字母a到z的两个或多个“单词”组成的字符串中,将最后一个“单词”替换为xxx

您可以在中阅读有关正则表达式的内容


如果你告诉我哪一部分很丑,你可能会告诉我你需要对哪一部分进行详细阐述?所有这些都是为了让任何新来者都能理解。我并不是说你的正则表达式很难看,而是说正则表达式一般来说很难看。:-)
s/^[a-z]+(?:_[a-z]+)*_\K[a-z]+\z/xxx/
^ \z: zero width assertions
[]: character class
+ *: quantifiers
(?: ): extended pattern (clustering)
\K: special escape
$aword = 'abc_def_ghi';
$aword =~ s/[^_]+$/xxx/;  # [^_]+$: to match non-underscore at the end of string.
print $aword  # => abc_def_xxx