久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

正則表達式匹配帶有可選的“www"和協議的

regex to match a URL with optional #39;www#39; and protocol(正則表達式匹配帶有可選的“www和協議的 URL)
本文介紹了正則表達式匹配帶有可選的“www"和協議的 URL的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試編寫一個正則表達式.

I'm trying to write a regexp.

一些背景信息:我嘗試查看我網站 URL 的 REQUEST_URI 是否包含另一個 URL.像這樣:

some background info: I am try to see if the REQUEST_URI of my website's URL contains another URL. like these:

  • http://mywebsite.com/google.com/search=xyz

但是,網址不會總是包含http"或www".所以模式也應該匹配像這樣的字符串:

However, the url wont always contain the 'http' or the 'www'. so the pattern should also match strings like:

  • http://mywebsite.com/yahoo.org/search=xyz
  • http://mywebsite.com/www.yahoo.org/search=xyz
  • http://mywebsite.com/msn.co.uk'
  • http://mywebsite.com/http://msn.co.uk'

有一堆正則表達式可以匹配 url,但我發現沒有一個可以在 http 和 www 上進行可選匹配.

there are a bunch of regexps out there to match urls but none I have found do an optional match on the http and www.

我想知道匹配的模式是否可能是這樣的:

i'm wondering if the pattern to match could be something like:

^([a-z]).(com|ca|org|etc)(.)

我想也許另一個選擇是匹配任何包含點 (.) 的字符串.(因為我的應用程序中的其他 REQUEST_URI 通常不包含點)

I thought maybe another option was to perhaps just match any string that had a dot (.) in it. (as the other REQUEST_URI's in my application typically won't contain dots)

這對任何人都有意義嗎?我真的很感謝在這方面的幫助,因為它已經阻止了我的項目數周.

Does this make sense to anyone? I'd really appreciate some help with this its been blocking my project for weeks.

非常感謝-蒂姆

推薦答案

我建議使用一種簡單的方法,基本上是建立在你所說的基礎上,只是任何帶有點的東西,但也使用正斜杠.捕獲所有內容而不會錯過不尋常的 URL.所以就像:

I suggest using a simple approach, essentially building on what you said, just anything with a dot in it, but working with the forward slashes too. To capture everything and not miss unusual URLs. So something like:

^((?:https?://)?[^./]+(?:.[^./]+)+(?:/.*)?)$

它讀作:

  • 可選 http://或 https://
  • 非點或正斜杠字符
  • 一組或多組點后跟非點或正斜杠字符
  • 可選的正斜杠及其后的任何內容

將整個事物捕獲到第一個分組.

Capturing the whole thing to the first grouping.

它會匹配,例如:

  • nic.uk
  • nic.uk/
  • http://nic.uk
  • http://nic.uk/
  • https://example.com/test/?a=bcd

驗證它們是有效的 URL 是另一回事!它也會匹配:

Verifying they are valid URLs is another story! It would also match:

  • index.php

它不會匹配:

  • 目錄/index.php

最小匹配基本上是something.something,其中沒有正斜杠,除非它在點之后至少出現一個字符.因此,請確保不要將這種格式用于其他任何用途.

The minimal match is basically something.something, with no forward slash in it, unless it comes at least one character past the dot. So just be sure not to use that format for anything else.

這篇關于正則表達式匹配帶有可選的“www"和協議的 URL的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發技術
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網站的單一入口點.壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 日韩中文字幕一区 | 精品国产免费一区二区三区演员表 | 日韩欧美在线播放 | 国产精品夜间视频香蕉 | 成人精品免费视频 | 亚洲一区视频在线 | 亚洲iv一区二区三区 | 成人视屏在线观看 | 欧美日韩国产高清 | 国产一区在线免费观看 | 一区二区三区四区不卡 | 免费国产视频 | 国产亚洲精品一区二区三区 | 日韩成人在线播放 | 黄免费在线 | 九九综合 | 国产精品乱码一区二三区小蝌蚪 | 国产www成人 | 在线观看国产 | 精品久久中文字幕 | 欧美在线视频观看 | 麻豆一区二区三区 | 一级做a爰片久久毛片免费看 | 综合久久综合久久 | 中文字幕成人 | 最新一级毛片 | 国产毛片毛片 | 日韩成人中文字幕 | 中文字幕亚洲视频 | 日日精品 | 亚洲精品久久久一区二区三区 | 日韩欧美理论片 | 日韩欧美中文字幕在线视频 | 一区二区三区不卡视频 | 亚洲一区二区三区在线视频 | 亚洲综合免费 | www.中文字幕.com | 综合网视频 | 国产在线一 | 色资源在线 | 大吊一区二区 |