tags:

views:

95

answers:

2

I need a regex to replace '''string''' with <b>string</b>

this one wont work: '/'''(.*?)'''/'

+2  A: 

Make sure to escape the single quotes with backslashes:

'/\'\'\'(.*?)\'\'\'/'

Or just use double quotes in which case you don't have to worry about escaping single quotes:

"/'''(.*?)'''/"
yjerem
thanks. do you maybe know why the same wont work with: "/[[(.*?)]]/"
@Dremex, the square brackets introduce a character class unless they are escaped. Try '/\[\[(.*?)\]\]/' instead.
pilcrow
+1  A: 
$string = "guns '''hurt''' people";

echo preg_replace ("/'''(.*)'''/", '<b>$1</b>', $string);
camomileCase
You'd need to escape the square brackets as well... "/\[\[(.*?)\]\]/" Square brackets are used for character classes. http://www.php.net/manual/en/regexp.reference.squarebrackets.php
camomileCase