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. 統計外連點擊次數的WordPress外掛:WP Click Info 
  2. Joomla! 1.0.12網站建置3-如何預覽版面位置 
  3. [TS-109] 掛載ISO檔案的命令 
  4. [Tools] 真正免費的Free Download Manager (3)
  5. 幫部落格加上Plurk快速噗文按鈕[修訂] (8)
  6. 附中71學年度畢業班紀念休閒服 (3)
  7. Firefox: 使用者自訂檔 
  8. [轉貼] 人氣部落客 廣告費月入萬元 
  9. [iReport] 奇偶列變換底色 
  10. [轉貼] LinuxTW — 台灣的 Linux 入口站 

歷史熱門文章

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