Bobby B
Bobby B

Reputation: 2402

Modifying captured tokens from a regular expression?

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

Upvotes: 1

Views: 68

Answers (2)

mcandre
mcandre

Reputation: 24612

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

Upvotes: 0

kennytm
kennytm

Reputation: 523364

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

Upvotes: 1

Related Questions