Extracting Text from between parentheses in PHP using preg_replace

Posted by Christopher on Stack Overflow See other posts from Stack Overflow or by Christopher
Published on 2010-03-27T00:27:21Z Indexed on 2010/03/27 0:33 UTC
Read the original article Hit count: 383

I am trying to take a string of text like so:

$string = "This (1) is (2) my (3) example (4) text";

In every instance where there is a positive integer inside of parentheses, I'd like to replace that with simply the integer itself.

The code I'm using now is:

$result = preg_replace("((\d+))", "$0", $string);

But I keep getting a "Delimiter must not be alphanumeric or backslash" error.

Any thoughts? I know there are other questions on here that sort of answer the question, but my knowledge of regex is not enough to switch it over to this example.

© Stack Overflow or respective owner

Related posts about php

Related posts about preg-replace