我是正则表达式的新手,谁能帮我弄清楚这行说的是什么:
$body = preg_replace('/\s{6,}/ms','',$body);
提前致谢。
我是正则表达式的新手,谁能帮我弄清楚这行说的是什么:
$body = preg_replace('/\s{6,}/ms','',$body);
提前致谢。
$body = preg_replace('/\s{6,}/ms','',$body);
Replace space (\s
), which occurs 6 to undefined times ({6,}
) with nothing. Do this multiline. (/m
). The s
could be removed, it adds no value when you don't use the "all characters" character (.
).
它删除了至少 6 个连续的空白字符的出现。
\s - 空白
定义为(水平)制表符、空格、换行、回车或换页。
模式修饰符是无用的顺便说一句:
m
改变和的^
行为$
s
也.
匹配换行符;否则它将停在一行的末尾。基本上它的说法是用连续六个空格替换任何东西。
\s = space
{6,} = between 6 and (since the second number after the comman is blank) 6
\ms = Used together, as /ms, they let the "." match any character whatsoever, while still allowing "^" and "$" to match, respectively, just after and just before newlines within the string.
还可以看看perldoc 中的 perl 正则表达式,将来可能会有所帮助。