$regex = '#<code>(.*?)</code>#';
Using #
as the delimiter instead of /
because then we don't need to escape the /
in </code>
As Phoenix posted below, .*?
is used to make the .*
("anything") match as few characters as possible before it comes across a </code>
(known as a "non-greedy quantifier"). That way, if your string is
<code>hello</code> something <code>again</code>
you'll match hello
and again
instead of just matching hello</code> something <code>again
.