Cara kerja pola
| Bagian | Arti |
|---|---|
https? | http atau https |
:\/\/ | Karakter tepat :// |
[^\s<>"']+ | Semua karakter sampai ketemu spasi, tanda kurung sudut, atau tanda kutip |
Contoh kode
JavaScript
const matches = text.match(/https?:\/\/[^\s<>"']+/g) ?? [];Python
import re
matches = re.findall(r'''https?://[^\s<>"']+''', text)PHP
preg_match_all('/https?:\/\/[^\s<>"\']+/', $text, $m);
$matches = $m[0];
Catatan dan batasan
Tanda baca di akhir, seperti titik akhir kalimat, ikut tertangkap sebagai bagian dari URL; hapus [.,;:!?)]+$ dari setiap kecocokan.
Regex Tester
Ketik pola dan lihat hasil cocok langsung ter-highlight di teks ujimu.