tags:

views:

23

answers:

2

Using a general regular expression replacement (for me, I'm doing this through TextMate) is it possible to modify a captured token?

I've essentially got a handful of enums that I want to modify...

CONSTANT get { return 1; }
CONSTANT get { return 2; }
CONSTANT get { return 3; }

What I'd like to do is capture the "return x"...

return [\d]

... but then modify the return value by decrementing by 1

$1-1

Is there anyway to do this purely using regexps?

TIA!

Bob

+1  A: 

It can't be done purely using regexes. Arithmetics isn't a capability of regex. You need to write a script.

KennyTM
S'what I figured. But, assumptions, you know...
Bobby B
That's what I thought, but I figured I'd ask just to be certain. Thanks for the answer.
Bobby B
A: 

Use a regex that replaces 9 with 8, 8 with 7, 7 with 6, etc.

mcandre