Regex to change numbers to a value 1 step lower
-
i have a regex that i use that changes numbers and increases the value, so if theres a 1 in my txt i turns it into 2, a 0 to 1 and so. Ive been trying to make a new regex that decreases value by 1, so it would turn a 4 into a 3, a 9 into an 8 and so on. But im stuck i cant figure it out, ill post the current regex i use and some examples
find
(0)|(1)|(2)|(3)|(4)|(5)|(6)|(7)|(8)|(9)replace with
(?{1}1)(?{2}2)(?{3}3)(?{4}4)(?{5}5)(?{6}6)(?{7}7)(?{8}8)(?{9}9)(?{10}0)Now im wondering if its possible to use this same formula but to decrease the numbers
examples
james66
fire1
dog 2
lier9
to
james55
fire0
dog1
lier8
-
Hello, @pablo-martinez,
I’ve just missed your post, till now ! Really easy, indeed !
The search regex is unchanged
(0)|(1)|(2)|(3)|(4)|(5)|(6)|(7)|(8)|(9)
The replacement regex becomes
(?{1}9)(?{2}0)(?{3}1)(?{4}2)(?{5}3)(?{6}4)(?{7}5)(?{8}6)(?{9}7)(?{10}8)
Remark : I noticed that, in your previous regex, when you add
1
to digit9
, you get the0
digit ( part(?{10}0)
, at the end of your previous replacement regex ).So, to stay coherent, with that method, now, if you subtract
1
from0
, you’ll get the number9
( part(?{1}9)
, at the beginning of the new replacement regex ! )Best Regards,
guy038