Question

I'd like to know whether there is a way to match an integer and its sucessor:

I'd like to match: "1 Victor 2 Marconi"

But not: "1 Victor 3 Marconi"

Is there a way to backreference the first number and increment it like: (\d) [[:alpha:]]* \1 +1 [[:alpha:]]* (INVALID)

I don't know if regexp is the right tool. If not, what would it be ?

Was it helpful?

Solution

You can't do arithmetics with regex. You could possibly create a really big regex which replaces a limited number of numbers by their successor, but not in general.

When incrementing, there is always the possibility of a carry -> 9+1=10.

Why do you want to do it with a regex, anyway?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top