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.
您可能也會有興趣的類似文章
- Xuite再度變身! (0則留言, 2007/08/31)
- [工具] Xuite人氣統計網頁 (5則留言, 2007/09/16)
- 用樣式控制Google AdSense廣告顯示的位置 (13則留言, 2007/05/03)
- 對Xuite的小小抱怨 (8則留言, 2005/06/03)
- Xuite新功能?文章標籤、歷史上的今天與隨機推薦文章 (0則留言, 2008/06/14)
- Xuite新功能上線 (0則留言, 2007/08/08)
- 變更Xuite回應的排列順序 (5則留言, 2007/09/17)
- 本部落格的連線速度問題 (1則留言, 2007/12/31)
- 幫Xuite增加單篇文章的雙擊快速編輯功能 (1則留言, 2007/08/15)
- 「網頁載入中,請稍候...」的簡單作法 (17則留言, 2007/05/02)
- Xuite存檔失敗的小小問題 (1則留言, 2008/03/26)
- Xuite新功能上線? (0則留言, 2008/05/15)
- 在Xuite測試 jQuery (0則留言, 2007/09/12)
- [Xuite] Xuite上的空間又多了500MB (1則留言, 2005/05/15)
- [Blog] 在文章底部隨機顯示相關文章的功能說明 (6則留言, 2007/04/26)















另一個regular expression site: http://regexpal.com/