perl regexp最小匹配下划线之前的单词
我可以知道如何为这个案例编写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 您可以在中阅读有关正则表达式的内容 如果你告诉我
$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