You'll need to think pretty hard about what chars are part of an image url and what chars might be a delimiter. Giving examples of images to be found is one thing, distilling those examples into a set of guidelines for recognizing image urls is something else.
You might find this script handy. I use it for testing regular expressions. It assumes magic_quotes are OFF.
<?php
require_once '_top.php';
if($_POST['Submit']) {
$pattern=$_POST['pattern'];
if (!$pattern) {
$error = "You didn't enter a pattern!";
}
$string=$_POST['string'];
if (!$string) {
$error = "You didn't enter a string to be searched!";
}
if ($error) {
show_form($error, $_POST);
} else {
// do the pattern match
$matches = Array();
$num_matches = preg_match_all($pattern, $string, $matches);
if ($num_matches == 0) {
$error = "NO MATCHES";
show_form($error, $_POST);
} else {
show_form('', $_POST, $matches);
} // if matches found
}
} else {
show_form();
}
function report_html3($str_arg) {
echo "<pre style='background-color:#eeeeee;'>" .
htmlentities($str_arg) .
"</pre>\n";
}
function show_form($error='', $data=Array(), $matches=Array()) {
?>
<html>
<head>
<title>Regular Expression Tester</title>
</head>
<body>
<h1>Testing Regular Expressions</h1>
<?
if ($error) {
echo "<div style='color:#ff0000'>" . $error . "</div>\n";
}
?>
<p>This form allows you to test a regular expression using <a href="http://php.net/preg_match_all">preg_match_all()</a></p>
<form method=POST>
String:<br>
<textarea name='string' cols='100' rows='10'><?=htmlentities($data['string']) ?></textarea><br><br>
RegEx Pattern:<br>
<input type=text name="pattern" size=100 value="<?= htmlentities($data['pattern']) ?>"><br><br>
<input type=submit value="Test Pattern" name="Submit">
</form>
<?
$num_matches = sizeof($matches[0]);
if ($num_matches > 0) {
echo "<hr>";
echo "<h2>" . $num_matches . " MATCHES</h2>";
foreach($matches as $key1=>$matches1) {
foreach ($matches1 as $key2=>$value) {
echo "<b>Match " . $key1 . "-" . $key2 . "</b>\n";
report_html3($value);
} // for each match
} // for MAIN MATCH
} // if matches
?>
</body></html>
<?
} // show_form()
?>