亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: 正則表達式:英文字符斷句 [打印本頁]

作者: ubac    時間: 2007-03-15 16:09
標(biāo)題: 正則表達式:英文字符斷句
1、Spring's color fill the garden but cannot all be contained!
如果字符串中間有空格的話,不需要斷句;
2、 Spring'scolorfillthegardenbutcannotallbecontained!
如果字符串中間沒有空格,這樣的話,需要每格十個英文字符斷一次句
即:Spring'sco lorfillthe gardenbutc annotallbe contained!
不知道該如何匹配斷句?
作者: ulmer    時間: 2007-03-15 17:07
標(biāo)題: 回復(fù) 1樓 ubac 的帖子
Hi,
i.e. 4U:

  1. @strings = (
  2.     "Spring's color fill the garden but cannot all be contained!",
  3.     "Spring'scolorfillthegardenbutcannotallbecontained!"
  4. );

  5. for (@strings) {
  6.     if (! /\s/) {
  7.         @a = /.{10}/g;
  8.         print "@a\n";
  9.     }
  10. }
復(fù)制代碼


-- ulmer
作者: ubac    時間: 2007-03-15 19:35
呵呵,謝謝~~
剛想到一個有意思的:
如果字符串為:
Spring's color Spring'scolorfillthegardenbutcannotallbecontained!
  fill the garden but cannot all be contained!
對于字符串中的每個“單詞”,如果其長度大于十,那么就每十個字符截斷一次,否則正常輸出
作者: yt_Wang    時間: 2007-03-16 15:36
$str="Spring'scolorfillthegardenbutcannotallbecontained!";

while($str =~ /(.{1,10})/g) {
  print "$1 ";
}
print "\n";




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2