Forum Moderators: coopster

Message Too Old, No Replies

Regular Expression Problem

         

rfontaine

2:20 pm on Jul 28, 2005 (gmt 0)

10+ Year Member



Hi,

I admit I am terrible at regex. I have some pages with a bunch of text, within which includes:

top:1234
top:1244
top:1264
etc

I would like to subtract 1000 from all the numbers associated with "top:" only, and no other numbers.

Here is my (bad) regex attempt, but alas, it does not seem to work...any ideas?

$content = preg_replace("/top:([0-9]*)$1/i",${1} - 1000,$content);

Any help greatly appreciated.

dcrombie

3:16 pm on Jul 28, 2005 (gmt 0)



The e modifier makes preg_replace [php.net] treat the replacement parameter as PHP code after the appropriate references substitution is done.

;)

rfontaine

5:48 pm on Jul 28, 2005 (gmt 0)

10+ Year Member



You mean like this?

$content = preg_replace("/top:([0-9]*)$1/e",${1} - 1000,$content);

[edited by: jatar_k at 6:23 pm (utc) on July 28, 2005]
[edit reason] turned off smilies [/edit]

dcrombie

11:04 am on Jul 29, 2005 (gmt 0)



Close (-;

$content = preg_replace("/top:([0-9]+)/e", "\$1 - 1000", $content);