Community
    • Login

    Help with a... distant replacement?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 4 Posters 1.2k 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.
    • HeyImAName HeyImALastNameH Offline
      HeyImAName HeyImALastName
      last edited by

      So, I have lines like this:

      		"LOC_FN_StandardShield1Novice": "$[[LOC_FN_DankSorter_SpellTier1]]Protect",
      		"LOC_FN_StandardShield2Apprentice": "$[[LOC_FN_DankSorter_SpellTier2]]Defend",
      

      And I want to copy the initial LOC_FN string and use it to replace the name at the end of the lines, like this:

      		"LOC_FN_StandardShield1Novice": "$[[LOC_FN_DankSorter_SpellTier1]]$[["LOC_FN_StandardShield1Novice"]]",
      		"LOC_FN_StandardShield2Apprentice": "$[[LOC_FN_DankSorter_SpellTier2]]$[["LOC_FN_StandardShield2Apprentice"]]",
      

      I’ve looked through the documentation of RegEx a bit, and found that I can use

      ].*"
      

      with Regular Expression checked to find all the names I want replaced, but I’m not experienced in this sort of thing and couldn’t quite wrap my head around how to tell it to replace that match with the string at the start of the line it’s on. Is there a way?

      Alan KilbornA 1 Reply Last reply Reply Quote 1
      • Alan KilbornA Offline
        Alan Kilborn @HeyImAName HeyImALastName
        last edited by

        @HeyImAName-HeyImALastName

        Wow, that is really non-trivial.
        But I’d say to try starting with this regular expression replacement:

        Find: (?-s)^(\t*"(.+?)": "\$\[{2}.+?\]{2}).+?,
        Replace: ${1}$[["${2}"]]",

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

          @heyimaname-heyimalastname, @alan-kilborn and All,

          Just a variant of the Alan’s search-replacement where the leading indentation and the ", trailing string are NOT taken in account, in search :

          FIND (?-s)(([^\h:\r\n]+).+?)\w+(?=",$)

          REPLACE \1$[[\2]]

          For a similar result !

          Best Regards,

          guy038

          1 Reply Last reply Reply Quote 1
          • Mark OlsonM Offline
            Mark Olson
            last edited by

            @HeyImAName-HeyImALastName
            This looks like JSON to me. While you may be able to achieve your desired result using regex alone, please be warned that JSON is meant to be parsed by a JSON parser, so you may find it easier to use a scripting language to parse the file before working with regular expressions.

            1 Reply Last reply Reply Quote 1
            • HeyImAName HeyImALastNameH Offline
              HeyImAName HeyImALastName @Alan Kilborn
              last edited by

              @Alan-Kilborn said in Help with a... distant replacement?:

              @HeyImAName-HeyImALastName

              Wow, that is really non-trivial.
              But I’d say to try starting with this regular expression replacement:

              Find: (?-s)^(\t*"(.+?)": "\$\[{2}.+?\]{2}).+?,
              Replace: ${1}$[["${2}"]]",

              Wow, that looks like absolute gibberish to me, I can’t decipher it in the slightest. But I tried it and it worked perfectly! Thanks for your help, and everyone else who replied.

              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