ShaolinF Posted April 19, 2010 Share Posted April 19, 2010 Hi Guys, I have the following tag (minus the spaces): [ QUOTE=test ]testes sdfsdf[ /quote ] I have written the following regex which will hopefully get the name 'test' from that tag, see below (minus the space before the quote word): /^\[ quote=(.*)[\]\z]/ However, when I specify the replacement string the regex returns the whole tag instead of just the name: <div class="nm">$1</div> $message = preg_replace('/^\[quote=(.*)[\]\z]/', '<div class="nm">$1</div>', $message); returns: <div class="nm">[ QUOTE=test ]testes sdfsdf[ /quote ]</div> Anyone know where Im going wrong ? . P.S. I have to use preg_replace for this problem. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 19, 2010 Share Posted April 19, 2010 Your regular expression is looking for "quote", not "QUOTE". You need to make it case insensitive. Also, using "(.*)" is not efficient. Also, since you also need to replace the ending tag you should just do a search/replace for the name and message. Try this $message = preg_replace('/^\[quote=([^\]]*)\]([^\[]*)\[\/quote\]/i', "<div class='nm'>$1</div>\n$2", $message); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.