[問題] 關於含空白的跨行比對樣式-該如何寫?

看板Perl作者 (ing)時間19年前 (2006/09/21 18:16), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
請教各位前輩 現在小弟碰到的問題是: 我用 lynx 去向某網站要回一個網頁,放在 $str 中, 打算要由$str中抓出其中一段的資料。 它的資料格式是這樣 blahblahblahblah [3.jpg] 欄位1 欄位2 欄位3 欄位4 資料1 資料2 資料3 資料4 [4.jpg]blahblahblahblah 我試過 if($str =~ /(3.jpg)(.)(4.jpg)/s) 跟 if($str =~ /(3.jpg)([\s\S]*)(4.jpg)/s) 但是都沒有比對成功。想請教在這樣的狀況下(要取的字串包括字元、空白跟換行), REGEX 該怎麼寫呢? -- And they... Will dance if they want to dance Please brother take a chance You know they're gonna go Which way they wanna go All we know is that we don't know What is gonna be Please brother let it be Life on the other hand won't let you understand Why we're all part of the masterplan _ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.22.18.89 ※ 編輯: iFEELing 來自: 163.22.18.89 (09/21 18:26)

09/21 21:44, , 1F
其實有點看不懂你想抓的資料..可以再講清楚點嗎?
09/21 21:44, 1F
喔耶 用 /(\[3.jpg\])(.*)(\[4.jpg\])/s 就抓出中間的字串了 :) 感謝您的回應 ^^ ※ 編輯: iFEELing 來自: 220.134.244.196 (09/21 22:33)
文章代碼(AID): #154cQ1Ua (Perl)
文章代碼(AID): #154cQ1Ua (Perl)