Community
    • Login

    Trim xml attribute

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 3 Posters 3.0k Views 2 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.
    • MrKhad123M Offline
      MrKhad123
      last edited by

      I have a large group of xml files that were generated to a specification where one attribute

      dealerCustName=“This is the attribute there are many of them”

      I need to be able to Trim the value of all of these attributes to 25 characters.

      dealerCustName = “123456789012345678901234567890123456789”

      needs to be this

      dealerCustName = “1234567890123456789012345”

      The attribute needs to be truncated to 25 chars regardless of the content.

      Scott SumnerS 1 Reply Last reply Reply Quote 0
      • Scott SumnerS Offline
        Scott Sumner @MrKhad123
        last edited by

        @MrKhad123

        One way would be thus:

        Find what zone: (?-i)(dealerCustName\s*=\s*")([^"]{25})[^"]+"
        Replace with zone: \1\2"
        Search mode: Regular expression

        If you can’t figure that out, just say so and it will be explained. :-D

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

          Hello, @mrkhad123,

          An other formulation could be :

          SEARCH (?-i)^dealerCustName\h*=\h*"\d{25}\K\d*

          REPLACE Leave EMPTY

          OPTION Wrap around and Regular expression

          ACTION Click on the Replace All button, exclusively

          … and same remark as Scott’s one !

          Best Regards,

          guy038

          Scott SumnerS 1 Reply Last reply Reply Quote 1
          • Scott SumnerS Offline
            Scott Sumner @guy038
            last edited by

            @guy038

            I had \K in my regular expression at first as I played wit it. Then I remembered that Notepad++ has trouble sometimes with it when using the “walking replace” (definition: using Replace to walk through and selectively replace text). I think most people (especially regex newbies) prefer to walk through some replacements first to build confidence that a search expression is correct before hitting Replace All. Thus I tend to not propose \K solutions here (I tend to capture everything leading up to where the \K would be into a group, and then use that group at replacement time to re-insert the text).

            Of course, maybe this is a case where \K will work with the walking-replace; not sure, didn’t try. ;-)

            1 Reply Last reply Reply Quote 2
            • MrKhad123M Offline
              MrKhad123 @Scott Sumner
              last edited by

              @Scott-Sumner Beautiful! That is exactly what I was looking for! Is there a place where I can find syntax for these types of replacements?

              Scott SumnerS 1 Reply Last reply Reply Quote 1
              • Scott SumnerS Offline
                Scott Sumner @MrKhad123
                last edited by

                @MrKhad123

                Some good references relating specifically to Notepad++ are:

                • general: http://docs.notepad-plus-plus.org/index.php/Regular_Expressions
                • find-specific: http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html
                • replace-specific: http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

                Also, some other general references I like are:

                • https://www.regular-expressions.info/
                • http://www.rexegg.com/
                MrKhad123M 1 Reply Last reply Reply Quote 2
                • MrKhad123M Offline
                  MrKhad123 @Scott Sumner
                  last edited by

                  @Scott-Sumner

                  Thanks again Scott.
                  You have been of great help.

                  1 Reply Last reply Reply Quote 1

                  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