我最近一直在学习\x
Perl Best Practices 中的修饰符,使您能够做一些很酷的事情,比如多行缩进和文档:
$txt =~ m/^ # anchor at beginning of line
The\ quick\ (\w+)\ fox # fox adjective
\ (\w+)\ over # fox action verb
\ the\ (\w+) dog # dog adjective
(?: # whitespace-trimmed comment:
\s* \# \s* # whitespace and comment token
(.*?) # captured comment text; non-greedy!
\s* # any trailing whitespace
)? # this is all optional
$ # end of line anchor
/x; # allow whitespace
但是,我无法为查找/替换字符串替换做同样的事情?是否应该使用其他类似的最佳实践来更有效地管理复杂的替换?
编辑以这个为例:
$test =~ s/(src\s*=\s*['"]?)(.*?\.(jpg|gif|png))/${1}something$2/sig;
是否有类似的方法可以使用多行/空白进行记录以提高可读性?
非常感谢