preg_replace: Regular Expression question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mboer
Forum Newbie
Posts: 2
Joined: Sat May 17, 2008 2:11 pm

preg_replace: Regular Expression question

Post by mboer »

If I have the following string:

Code: Select all

$string = "John went all-in after he saw the flop (7s 8c 9d) and feels good about it.";
How would I go about setting up the regular expression so I can only replace between the ( ) brackets?

The basic pattern would be something like:

Code: Select all

preg_replace('/7s/', 'Seven of Spades', $string);
I'd appreciate any help, thx!
Post Reply