Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Trim xml attribute

    Help wanted · · · – – – · · ·
    3
    7
    1974
    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.
    • MrKhad123
      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 Sumner 1 Reply Last reply Reply Quote 0
      • Scott Sumner
        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

        MrKhad123 1 Reply Last reply Reply Quote 1
        • guy038
          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 Sumner 1 Reply Last reply Reply Quote 1
          • Scott Sumner
            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
            • MrKhad123
              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 Sumner 1 Reply Last reply Reply Quote 1
              • Scott Sumner
                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/
                MrKhad123 1 Reply Last reply Reply Quote 2
                • MrKhad123
                  MrKhad123 @Scott Sumner last edited by

                  @Scott-Sumner

                  Thanks again Scott.
                  You have been of great help.

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post
                  Copyright © 2014 NodeBB Forums | Contributors