Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Php matches the regular expression of the URL

Shulou Source: shulou.com Published: 2022-06-02 06:22:47 10月31日 Update

This article mainly explains the "regular expression of php matching URL". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "regular expression of php matching URL".

It's simple.

$str =''; $isMatched = preg_match ('/ ^ ^ ((https | http | ftp | rtsp | mms)?:\ /\ /) [^\ s] + $/', $str, $matches); var_dump ($isMatched, $matches)

It can match almost any URL:

^ ((https? | ftp | news):\ / /)? ([Amurz] ([a-z0-9\ -] * [\.]) + ([amurz] {2} | aero | arpa | biz | com | edu | gov | info | int | jobs | museum | nato | net | org | pro | travel) | ([0-9] | [1-9] [0-9] | 1 [0-9] {2} | 2 [0-4] [0-9] | 25 [0-5])\. {3} ([0-9] | [1-9] [0-9] | 1 [0-9] {2} | 2 [0-4] [0-9] | 25 [0-5])) -\. ~] +) * (\ / ([a-z0-9 _\ -\.] *) (\? [a-z0-9 colors _\ -\.% = &] *)?)? (# [aMuz] [a-z0-9] *)? $

Example:

Function IsURL (urlString) {regExp = / ^ ((https? | ftp | news):\ /\ /)? ([Amurz] ([a-z0-9\ -] * [\.]) + ([amurz] {2} | aero | arpa | biz | com | edu | gov | info | int | jobs | museum | nato | net | org | pro | travel) | ([0-9] | [1-9] [0-9] | 1 [0-9] {2} | 2 [0-4] [0-9] | 25 [0-5])\. {3} ([0-9] | [1-9] [0-9] | 1 [0-9] {2} | 2 [0-4] [0-9] | 25 [0-5])) -\. ~] +) * (\ / ([a-z0-9 _\ -\.] *) (\? [a-z0-9 colors _\ -\.% = &] *)?)? (# [an a-z0 z] [a-z0-9] *)? $/ if (urlString.match (regExp)) return "is a url" Else return "not a url";} url = "; alert (IsURL (url)); Thank you for reading, the above is the content of" regular expression of php matching URL ". After the study of this article, I believe you have a deeper understanding of the problem of regular expression of php matching URL, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: URL rules expressions learning content examples that is ideas situations articles more knowledge knowledge points articles follow questions practice push research verification Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Docker NVidia MySQL Huawei