Community
    • Login

    Regex to change numbers to a value 1 step lower

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 3.6k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Pablo MartinezP Offline
      Pablo Martinez
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • guy038G Offline
        guy038
        last edited by

        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 digit 9, you get the 0 digit ( part (?{10}0), at the end of your previous replacement regex ).

        So, to stay coherent, with that method, now, if you subtract 1 from 0, you’ll get the number 9 ( part (?{1}9), at the beginning of the new replacement regex ! )

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 0

        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
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors