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
1to digit9, you get the0digit ( part(?{10}0), at the end of your previous replacement regex ).So, to stay coherent, with that method, now, if you subtract
1from0, you’ll get the number9( part(?{1}9), at the beginning of the new replacement regex ! )Best Regards,
guy038
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login