# Increase Last Int by One (Regex)

**URL:** <https://forum.kirupa.com/t/increase-last-int-by-one-regex/193203>\
**Category:** open source\
**Created:** [July 5, 2006, 5:30am UTC](https://forum.kirupa.com/t/increase-last-int-by-one-regex/193203 "2006-07-05T05:30:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_Wheeler](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Jeff\_Wheeler](https://forum.kirupa.com/u/Jeff_Wheeler)\
**Post date:** [July 5, 2006, 5:30am UTC](https://forum.kirupa.com/t/increase-last-int-by-one-regex/193203/1 "2006-07-05T05:30:55Z")

</div>

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).

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

```

🙂
