Skip to content

Instantly share code, notes, and snippets.

@Moc Moc/regex.php
Created Feb 19, 2019

Embed
What would you like to do?
<?php
$string1 = '<link href="/css/bs4-dynamic-fields-form-2.min.css" rel="stylesheet" media="screen">';
$string2 = '<script src="/cdn-cgi/apps/head/qx0HK83qWJ5I3r2xnETN-ETfo6s.js"></script>"';
$regex1 = '~<link(.*?)href="([^"]+)"(.*?)>~';
$regex2 = '/src=(["\'])(.*?)\1/';
$result1 = preg_match($regex1, $string1, $matches1);
$result2 = preg_match($regex2, $string2, $matches2);
var_dump($matches1[2]);
var_dump($matches2[2]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.