Watkin Parrot
Watkin Parrot

Reputation: 53

Correct preg_replace format

What is the correct preg_replace format to replace everything (including the brackets) between (xxxxxx). Example have string (not long) link this: AAAAABBBBB (AAAAABBBBB) and all I want is AAAAABBBBB. I need to use preg_replace as the string and it's string length changes.

Thanks

Upvotes: 0

Views: 52

Answers (1)

Kasia Gogolek
Kasia Gogolek

Reputation: 3414

Not sure if I understood your question right, but this should return the string insite the parentheses

$string = "CCCCC (AAAAABBBBB)";
return preg_replace("(.+\(|\))","",$string);

This regex will basically look for any string followed by ( and singular")" and replace them with "".

Upvotes: 0

Related Questions