Re: RegExp question: how to add a number?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux