free html hit counter
[JS][PHP] Regexp for matching URL Pattern
[JS][PHP] Regexp for matching URL Pattern
2018-11-23 / Dimas Lanjaka Kumala Indra

regexp Regexp Pattern Untuk mencocokkan semua jenis URL, kode berikut seharusnya berfungsi:


<?php
$regex = “((https?|ftp)😕/)?”; // SCHEME
regex .= "([a-z0-9+!*(),;?&amp;=.-]+(:[a-z0-9+!*(),;?&=$.-]+)?@)?"; // User and Pass
$regex .= “([a-z0-9-.]).(([a-z]{2,4})|([0-9]{1,3}.([0-9]{1,3}).([0-9]{1,3})))"; // Host or IP
$regex .= “(:[0-9]{2,5})?”; // Port
regex.="(/([az09+regex .= "(/([a-z0-9+_%-].?)+)
/?”; // Path
regex .= "(\?[a-z+&amp;\$_.-][a-z0-9;:@&amp;%=+/.-]*)?"; // GET Query
regex .= "(#[a-z_.-][a-z0-9+%
.-]*)?"; // Anchor
?>

Example: correctly way for matching URL


<?php
if(preg_match("^$regex$i", ‘www.example.com/etcetc’, m))<br>vardump(m))<br> var_dump(m);

if(preg_match("^$regex$i", ‘http://www.example.com/etcetc’, m))<br>vardump(m))<br> var_dump(m);
?>
Pattern diatas bisa digunakan di javascript. Bedanya dengan diatas hanya dari segi variablenya saja. Bila di PHP variable dituliskan dengan awalan ($) maka di javascript cukup diganti (var) atau (let) atau (const)

[JS][PHP] Regexp for matching URL Pattern

PermaLink: https://www.webmanajemen.com/2018/11/regexp-for-matching-url-pattern.html
Incoming search terms for [JS][PHP] Regexp for matching URL Pattern:
  • [JS][PHP] Regexp for matching URL Pattern
  • [JS][PHP] Regexp for matching URL Pattern WMI Gitlab

Google Rich Snippets | Schema Markup Validator | Google Pagespeed Insight