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. 希望:Plurk稍後會修正,請大家稍候… (1)
  2. Plurk CSS樣式自訂修改全攻略 (79)
  3. HTC Touch HD連結失效! 
  4. 如何用批次指令取得上個月的月份-再修訂版 (10)
  5. 示範Atahualpa 3.5.1佈景主題表頭區的調整 
  6. [轉貼] 全球掀熱潮 桃太郎最愛玩部落格 
  7. [Tools] Miranda-IM 外掛便利貼與鬧鈴 
  8. [iReport] JasperReport 文件下載 (2)
  9. [轉貼電腦報] HiNet推出Xuite,整合部落格、相簿、信箱及硬碟服務 (1)
  10. [iReport] 兩個文字元件:Static Text與Text Field 

歷史熱門文章

  1. 如何手動輸入Plurk的表情圖示? (368,207 點擊/2008-09-29)
  2. 啟用&關閉中華電信ZyXEL P874的無線網路連線功能的步驟[修訂] (119,945 點擊/2011-06-01)
  3. Plurk CSS樣式自訂修改全攻略 (89,384 點擊/2009-07-04)
  4. 簡單放大Plurk輸入區的方法[修訂] (88,868 點擊/2008-09-29)
  5. 網路升級光世代50M/3M與設定ZyXEL P874 (71,877 點擊/2011-05-28)
  6. 輕鬆學會彈指神功-揭露AutoHotkey絕技 (50,786 點擊/2008-04-10)
  7. iPad新手入門技巧 (49,252 點擊/2011-02-05)
  8. iPad鍵盤輸入全攻略 (42,712 點擊/2011-01-01)
  9. 分享世博台灣館主題曲『台灣的心跳聲』MV(附歌詞+下載連結+新歌詞) (40,865 點擊/2010-04-27)
  10. 調整Windows 7環境: 加回工作列的「顯示桌面」圖示 (40,745 點擊/2010-01-02)