Community
    • Login

    Locate and insert new value

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 411 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.
    • Gonka WeerakoonG
      Gonka Weerakoon
      last edited by

      Hi all,

      I need a big help to locate and insert value operation in np++
      Below you can see the required part from XML file. I need to locate <t_to> then <to_person> and insert <nationality1>US</nationality1> tag below the <ssn>
      tag.
      <t_to>
      <to_funds_code>CASH</to_funds_code>
      <to_person>
      <first_name>ANTHONAN BETHO PERERA</first_name>
      <last_name>GOTHEN</last_name>
      <ssn>6115456465465A</ssn>
      nationality1>US</nationality1>
      </to_person>
      <to_country>FR</to_country>
      </t_to>

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Gonka Weerakoon
        last edited by

        @gonka-weerakoon

        Using the technique shown HERE, this seems to do it:

        find: (?s-i:<t_to>.*?<to_person>|(?!\A)\G)(?s:(?!</to_person>.*?</t_to>).)*?\K(?-i:</last_name>\R)
        repl: $0<ssn>6115456465465A</ssn>\r\n
        mode: Regular expression

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

          Hello, @gonka-weerakoon, @alan-kilborn and All,

          @alan-kilborn, I"m surprised and don’t understand your regex replacement ! Perhaps, I’m missing something obvious !

          @gonka-weerakoon, if all your sections, below, contains <ssn>xxxxxxxxxxxx</ssn> matchings tags :

          <t_to>
              ...
              <to_person>
                  ...
                  ...
                  <ssn>6115456465465A</ssn>
              </to_person>
              ...
          </t_to>
          

          Then :

          • Open the Replace dialog ( Ctrl + H )

          • SEARCH (?s-i)<t_to>.*?<to_person>.*?</ssn>\R\K

          • REPLACE nationality1>US</nationality1>\r\n

          • Untick all options

          • Tick the Wrap around option

          • Select the Regular expression search mode

          • Click once on the Replace All button ( do not use the Replace button ! )

          In case that some sections <t_to>............</t_to> do not contain a <ssn>xxxxxxxxxxxx</ssn> part, just tell me in order to modify the search regex accordingly !

          Best Regards,

          guy038

          Alan KilbornA 1 Reply Last reply Reply Quote 2
          • Alan KilbornA
            Alan Kilborn @guy038
            last edited by

            @guy038 said in Locate and insert new value:

            I"m surprised and don’t understand your regex replacement

            I don’t understand it now either.
            For some reason I thought OP wanted to insert the ssn tag and value!
            Oops.

            1 Reply Last reply Reply Quote 1
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors