Skip to content

Instantly share code, notes, and snippets.

@Jimmi08
Forked from Moc/regex.php
Created February 19, 2019 21:30
Show Gist options
  • Save Jimmi08/0f54a6ab1284d8e095c10cedd30d3393 to your computer and use it in GitHub Desktop.
Save Jimmi08/0f54a6ab1284d8e095c10cedd30d3393 to your computer and use it in GitHub Desktop.
<?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