PDA

View Full Version : Increase Last Int by One (Regex)



Jeff Wheeler
July 5th, 2006, 01:30 AM
Here's a neat little thing… it'll increase the last number in a string by one. Very simple, but a nice little regex… it was inspired by a bookmarklet that does this to the URL (I didn't see the source for that).


function increase_number ($string) {
return preg_replace('/([0-9]+)([^0-9]*)$/e', '($1+1)."$2"', $string);
}

:)

Templarian
July 5th, 2006, 01:38 AM
lol. Nice one nokrev.

Jeff Wheeler
July 5th, 2006, 01:43 AM
It was really just one of those moments where you see something, and you try to do it yourself. :P

bigmtnskier
July 5th, 2006, 03:04 AM
:lol: Nice

I knew this was your thread by just seeing the title, lol :P

Jeff Wheeler
July 5th, 2006, 12:29 PM
:lol: