- 論壇徽章:
- 1
|
hs3605306 發(fā)表于 2012-01-08 14:44 ![]()
回復(fù) 11# MayIKissU
其實(shí)這個(gè)問(wèn)題的實(shí)質(zhì)是如果用~ /^.*$/ 去做匹配,它會(huì)無(wú)視string 中的\n,所以問(wèn)題不 ...
By default, the "^" character is guaranteed to match only the beginning of the string, the "$" character only the end (or before the newline at the end), and Perl does certain optimizations with the assumption that the string contains only one line. Embedded newlines will not be matched by "^" or "$". You may, however, wish to treat a string as a multi-line buffer, such that the "^" will match after any newline within the string (except if the newline is the last character in the string), and "$" will match before any newline. At the cost of a little more overhead, you can do this by using the /m modifier on the pattern match operator. (Older programs did this by setting $* , but this option was removed in perl 5.9.)
$會(huì)匹配\n的前面位置. |
|