Sublime Forum

Regex replace with math

#1

Hi i want to know if it is possible to replace text with regex and do some math operation.

x10 y10 -> xy20

I would search this with
x(…) y(…)

and replace it with ?

xy($1+$2) ? (don’t know what operation to use)

0 Likes

#2

Regular expressions can’t do this. However, many languages’ regex libraries (such as Python’s) have the ability to pipe the replacement through a function. You could write a plugin.

0 Likes