Chinaunix

标题: 正则表达式问题, 单行, 多行?? [打印本页]

作者: nhw_cs    时间: 2011-11-10 12:00
标题: 正则表达式问题, 单行, 多行??
如果目标字符串中间插入\n, 模式匹配修饰符s代表将目标字符串做为单行处理, m 则视为多行。

但如果这两个修饰符都不加, 缺省如何处理呢?
作者: zhlong8    时间: 2011-11-10 12:29
s 只影响 . m 只影响 ^$
作者: nhw_cs    时间: 2011-11-10 12:56
s 只影响 . m 只影响 ^$
zhlong8 发表于 2011-11-10 12:29



    也就是说, 缺省的处理既不同于单行, 也不同于多行?
作者: zhlong8    时间: 2011-11-10 13:06
也就是说, 缺省的处理既不同于单行, 也不同于多行?
nhw_cs 发表于 2011-11-10 12:56



   
m
Treat string as multiple lines. That is, change "^" and "$" from matching the start or end of the string to matching the start or end of any line anywhere within the string.
s
Treat string as single line. That is, change "." to match any character whatsoever, even a newline, which normally it would not match.
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.

作者: jason680    时间: 2011-11-10 13:41
本来无一物,何处惹尘埃
字符串字就是字符串...何来"缺省"字符串




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2