第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我有 preg_match_all 函數(shù)的問題

我有 preg_match_all 函數(shù)的問題

PHP
慕標(biāo)琳琳 2021-08-28 18:30:11
我不知道如何從此代碼中獲取全行內(nèi)容。$str = '#chapter 1: title 1content chapter 1 line 1content chapter 1 line 2content chapter 1 line 3content chapter 1 line 4#chapter 2: title 2content chapter 2 line 1';preg_match_all('/#Chapter ([0-9]+.?[0-9]?)\s?(<([0-9]+)>)?:(.*)(\s+.+\s+)/i',$str, $match);我試過這段代碼,這得到了這樣的內(nèi)容:$match[5][0]: 內(nèi)容章節(jié) 1 第 1 行$match[5][1]:內(nèi)容第二章第二行問題在: (\s+.+\s+)。我怎樣才能獲得全行內(nèi)容?!非常感謝。
查看完整描述

1 回答

?
慕哥9229398

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個贊

目前您只匹配一行。

您可以使用重復(fù)模式來匹配所有不以 #chapter 開頭的行,使用負(fù)前瞻:

#Chapter\h+\d+:\h+title\h+\d+\K(?:\R(?!#chapter).*)*

解釋

  • #Chapter 字面匹配

  • \h+\d+: 匹配 1+ 個水平空白字符、1+ 個數(shù)字和 :

  • \h+title\h+\d+匹配 匹配 1+ 個水平空白字符,title匹配 1+ 個水平空白字符和 1+ 個數(shù)字

  • \K 忘記匹配的內(nèi)容

  • (?: 非捕獲組

    • \R(?!#chapter).* 匹配unicode換行序列并斷言直接在右邊的不是#chapter

  • )* 關(guān)閉捕獲組并重復(fù) 0+ 次

例如:


preg_match_all('/#Chapter\h+\d+:\h+title\h+\d+\K(?:\R(?!#chapter).*)*/i',$str, $match);

print_r($match[0]);

結(jié)果


Array

(

    [0] => 


content chapter 1 line 1

content chapter 1 line 2

content chapter 1 line 3

content chapter 1 line 4


    [1] => 


content chapter 2 line 1



)


查看完整回答
反對 回復(fù) 2021-08-28
  • 1 回答
  • 0 關(guān)注
  • 142 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號