Xuite網址的正規運算式測試

Xuite的網址真是找人麻煩。這當然是對不熟悉正規運算式的我才成立的。

經過分析,Xuite的網址有下列幾種Pattern:

網址 說明
1 http://blog.xuite.net/emisjerry/tech 首頁(Blog清單,第一頁)
2 http://blog.xuite.net/emisjerry/tech?p=2 首頁(Blog清單,第二頁)
3 http://blog.xuite.net/emisjerry/tech/11327060 某篇文章網頁;有文章編號表示是文章網頁
4 http://blog.xuite.net/emisjerry/tech/11327060#message 第一頁按回應的某篇文章
5 http://blog.xuite.net/emisjerry/tech/11327060#trackback 第一頁按引用的某篇文章
6 http://blog.xuite.net/emisjerry/tech/11157208?p=2 首頁第二頁的某篇文章網頁
7 http://blog.xuite.net/emisjerry/tech/11157208?p=2#message 按了回應後的某篇文章
8 http://blog.xuite.net/emisjerry/tech/11157208?p=2#trackback 按了引用後的某篇文章

我的目標是判斷目前網頁是某篇文章的全文,只有在文章內部才要加上 隨機的相關文章與Google AdSense廣告,在首頁(有第一頁到第十頁)則不顯示相關文章和廣告。

透過 reWork: a regular expression workbench 測試了半天,下列運算式似乎能正確判斷出文章內部:

^http://blog.xuite.net/.*/d+(?p=d+)?(#message|#trackback|)
^http://blog.xuite.net/ 以http://blog.xuite.net/ 開頭
因為斜線是特殊符號,必須用 來使用需要的正斜線
http://blog.xuite.net/
.* 後面接續的是任意符號
點(.) 是萬用字元,星號表示其前置字元出現0或多次
tech 或 365day等

http://blog.xuite.net/tech

/ 後面再接一個正斜線 http://blog.xuite.net//tech/
d+ 一或多個數字 數字是文章編號,遇到數字則表示目前網頁是在文章內部
(?p=d+)? 最後面的問號表示其前置字元是選擇性的(即可有可無);圓括號則表示形成字元群組,?表示要使用問號,再接p=和一組數字(d+) http://blog.xuite.net/emisjerry/tech/11157208?p=2

http://blog.xuite.net/emisjerry/tech/11157208 都會成立
(#message|#trackback|) #message或#trackback或空白 http://blog.xuite.net/emisjerry/tech/11157208?p=2#message

http://blog.xuite.net/emisjerry/tech/11157208?p=2#trackback

http://blog.xuite.net/emisjerry/tech/11157208?p=2

http://blog.xuite.net/emisjerry/tech/11157208

以下皆成立

經初步測試似乎可行。若您熟悉正規運算式的話,請協助驗證。Thanks.

您可能也會有興趣的類似文章

1則留言 »Xuite網址的正規運算式測試

填寫回應

 

 

 

您可使用這些HTML標籤

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

隨機文章

  1. ◎權充留言板……◎ (5)
  2. [轉貼] X File Explorer - 類似 Windows 的 Unix 檔案總管 (2)
  3. Microsoft My Phone:同步手機資料的網路服務 
  4. 用螢幕鍵盤來設定熱鍵:Qliner Hotkeys (1)
  5. Mailmoa: 另一個郵件檢查程式 
  6. [設備] 開始使用藍牙耳機HT820 (7)
  7. [Site] Blog平台新選擇:Xuite (3)
  8. 使用Memory Fox附加元件為Firefox進行定期記憶體瘦身 (3)
  9. WordPress瀏覽圖片的FancyBox外掛 (8)
  10. 宜蘭頭城農場與《死亡筆記本》 

歷史熱門文章

  1. 如何手動輸入Plurk的表情圖示? (353,084 點擊/2008-09-29)
  2. 簡單放大Plurk輸入區的方法[修訂] (86,929 點擊/2008-09-29)
  3. 啟用&關閉中華電信ZyXEL P874的無線網路連線功能的步驟[修訂] (84,013 點擊/2011-06-01)
  4. Plurk CSS樣式自訂修改全攻略 (83,120 點擊/2009-07-04)
  5. 網路升級光世代50M/3M與設定ZyXEL P874 (53,308 點擊/2011-05-28)
  6. 輕鬆學會彈指神功-揭露AutoHotkey絕技 (43,175 點擊/2008-04-10)
  7. iPad新手入門技巧 (40,425 點擊/2011-02-05)
  8. 分享世博台灣館主題曲『台灣的心跳聲』MV(附歌詞+下載連結+新歌詞) (38,151 點擊/2010-04-27)
  9. 把HTC Touch HD操作介面換成Spb Mobile Shell,美觀又便利! (37,955 點擊/2009-02-18)
  10. 另一套適用手機的影片轉檔工具:WinAVI 3GP/MP4/PSP/iPod Video Converter (35,922 點擊/2009-04-18)