Regex '''string''' to <b>string</b>

143 views Asked by At

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

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

2

There are 2 answers

2
Paige Ruten On BEST ANSWER

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:

"/'''(.*?)'''/"
1
camomileCase On
$string = "guns '''hurt''' people";

echo preg_replace ("/'''(.*)'''/", '<b>$1</b>', $string);