Community
    • Login

    Help with a... distant replacement?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 4 Posters 130 Views
    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
      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
        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
          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
            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
              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
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors