Here is a dump of my favourite regex samples.
<?php
// Replace Esperanto X notation user input with accented characters.
$value = 'cxaro auxto sxati igxi'; // A string to test
$patterns = array( '/sx/','/cx/','/gx/','/jx/','/ux/','/hx/','/Sx/','/Cx/','/Gx/','/Jx/','/Ux/','/Hx/');
$replacements = array( 'ŝ', 'ĉ', 'ĝ', 'ĵ', 'ŭ', 'ĥ', 'Ŝ', 'Ĉ', 'Ĝ', 'Ĵ', 'Ŭ', 'Ĥ');
$value = preg_replace($patterns, $replacements, $value);
echo $value;
?>
<?php
// Scrape movie quotes from a web site.
$url = 'http://www.rottentomatoes.com/m/gone_with_the_wind/quotes/';
$regex = '/<span class="line">(.+?)<\/span>/';
$data = file_get_contents($url);
preg_match_all($regex,$data,$match);
//print_r($match);
// The array is in 2 parts. We just need the second part, $match[1]
$quotes = array_rand($match[1],1);
$quote = $match[1][$quotes];
?>
