Voorbeeld in PHP
// Patterns
$pat = array();
$pat[] = '/\[url\](.*?)\[\/url\]/'; // URL Type 1
$pat[] = '/\[url=(.*?)\](.*?)\[\/url\]/'; // URL Type 2
$pat[] = '/\[img\](.*?)\[\/img\]/'; // Image
// ... more search patterns here
// Replacements
$rep = array();
$rep[] = '<a href="$1">$1</a>'; // URL Type 1
$rep[] = '<a href="$1">$2</a>'; // URL Type 2
$rep[] = '<img src="$1" />'; // Image
// ... and the corresponding replacement patterns here
// Run tests
foreach($DIRTY as $dirty)
{
$clean = preg_replace($pat, $rep, $dirty);
printf("D: %s\n", $dirty);
printf("C: %s\n", $clean);
printf("\n");
}
Bron: http://stackoverflow.com/questions/10458103/how-to-make-php-bb-codes-with-regexp
Meer informatie over UBB Codes: http://gathering.tweakers.net/forum/faq/ubb