On Thu, Oct 14, 2010 at 1:42 PM, Andre Polykanine <andre@xxxxxxxx> wrote: > But (attention, here it is!) if the string starts with > something like "Re[4]:", it should replace it by "Re[5]:". > Regular expressions do not support any mathematical operations. Instead, you need to use preg_match() to extract the number inside the brackets, increment it, and build a new string using simple concatenation (.). elseif ($start=="re[") { if (preg_match('/^re\[(\d+)\](.*)/i', $f['Subject'], $matches) > 0) { $f['Subject'] = 'Re[' . ($matches[1] + 1) . ']' . $matches[2]; } else { // no closing brace -- now what? } } David