Community
    • Login

    *Help* How to change multiple unknown text string with just one?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    27 Posts 6 Posters 3.0k 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.
    • Terry RT
      Terry R
      last edited by

      @Chuny_OK said in *Help* How to change multiple unknown text string with just one?:

      And then the file ends.

      I presume you mean the file gets truncated? In large files with some types of look-aheads there can be instances of this occuring, but I wouldn’t have thought this in your case.
      Try this alternative regex.
      Find What:(?-s)(.+?dateTimeHour.+\R<value>)\d+
      Replace With:\1xx

      Where xx is the number you wish to use, it can be any length i.e. 1, 3765 etc. In this case as we are capturing the previous line and a bit of the current line (so we only get the datetimehour values you want to change) we need to write it back, hence the \1 in front of the number you want to insert.

      Terry

      Chuny_OKC 1 Reply Last reply Reply Quote 2
      • Chuny_OKC
        Chuny_OK @Terry R
        last edited by Chuny_OK

        @Terry-R
        Hello Terry
        Doesn’t quite work.

        If I do that, the whole document gets replaced by the number I entered :(

        The strange thing is that when I first started this thread, the help I was getting was always working! And the files are still XML, the structure is quite similar, although the properties are different. So I don’t get why neither the first tips I was provided nor the new ones are working.

        Chuny_OKC Terry RT 2 Replies Last reply Reply Quote 0
        • Chuny_OKC
          Chuny_OK @Chuny_OK
          last edited by

          @Chuny_OK

          For instance, there’s another thing I’d like to change:

          <property name=“gameMinExposure” type=“float” container=“StaticArray” arraySize=“1”>
          <value>-14</value>

          This line appear multiple times along this large document, but with different values along the way.
          If I wanted to replace al those different values with just one (like -10 for example), I can’t do that.

          1 Reply Last reply Reply Quote 0
          • Terry RT
            Terry R @Chuny_OK
            last edited by

            @Chuny_OK said in *Help* How to change multiple unknown text string with just one?:

            the whole document gets replaced by the number I entered :(

            My regex works by capturing part of 1 line, then the first part of the next line. If the “whole” document is being replaced it suggests you don’t have many or most likely ANY CRLF (carriage return line feeds in it.

            When the file is loaded in Notepad++ by default the left side shows line numbers. Can you determine if it only contains 1 or a small number of lines? If so then I would need to do some more testing, but my initially reaction would be to change that regex to:
            Find What:(?-s)(.+?dateTimeHour.+\R?<value>)\d+
            This will not force a CRLF between the 2 lines, but if it exists then it will include it.

            Terry

            1 Reply Last reply Reply Quote 2
            • Terry RT
              Terry R
              last edited by

              Actually thinking further another amendment is needed so try
              Find What:(?-s)(.+?dateTimeHour.+?\R?<value>)\d+
              The .+? minimally tries to capture up to a possible CRLF sequence, and just beyond to the first (hopefully) sequence of the <value> tag.

              Terry

              Chuny_OKC 1 Reply Last reply Reply Quote 2
              • Chuny_OKC
                Chuny_OK @Terry R
                last edited by

                @Terry-R said in *Help* How to change multiple unknown text string with just one?:

                (?-s)(.+?dateTimeHour.+?\R?<value>)\d+

                Look mate,
                I uploaded the file here: https://www83.zippyshare.com/v/rHBggLMf/file.html

                Please look for lines like:

                **<property name=“dateTimeHour” type=“uint32” container=“StaticArray” arraySize=“1”>

                And/Or

                **<property name=“gameMinExposure” type=“float” container=“StaticArray” arraySize=“1”>

                Where the numbers between the <value> </value> tags can be different everytime you search for them.

                And see if it works for you.

                Thank you again.

                1 Reply Last reply Reply Quote 0
                • Terry RT
                  Terry R
                  last edited by Terry R

                  @Chuny_OK said in *Help* How to change multiple unknown text string with just one?:

                  And see if it works for you

                  Sadly my last regex was still not working. Getting to see the actual lines in the file has helped, having “indented” lines didn’t help.
                  So my latest version is
                  Find What:(?s-i)(gameMinExposure.+?)-*\d+(</value>)
                  Replace With:($1)123($2)

                  You would change the “gameMinExposure” to the correct tag name, such as the other one you were looking for “dateTimeHour”. Note I have added the -i to the modifier at the start of the line, the search string is case sensitive. So for example if your file had “Datetimehour” and this regex is looking for “dateTimeHour”, with the -i modifier it will NOT find it, this is by design. Remove the -i if you don’t care, then you can type the string in any format “DaTeTiMeHoUr” for example and it will find “datetimehour”, “DATETIMEHOUR” or any other combinations.

                  I also noted that the number to be replaced was sometimes negative. So my latest regex has to look for that possibility as well. If found, then it will be removed when writing the number back. So you type into the Replace With field the number you want (including a - at the front if desired) replacing the 123 there.

                  Terry

                  Chuny_OKC 1 Reply Last reply Reply Quote 2
                  • Chuny_OKC
                    Chuny_OK @Terry R
                    last edited by

                    @Terry-R

                    That’s amazing, Terry!
                    I will give it a try right now!

                    Thank you very much for all the help and quickness!

                    Chuny_OKC 1 Reply Last reply Reply Quote 1
                    • Chuny_OKC
                      Chuny_OK @Chuny_OK
                      last edited by

                      @Terry-R

                      So… Terry!
                      I’m very sorry to keep dragging you into this, but a new issue came up.
                      It looks like when the value has a decimal, when I use the string you provided, it only replaces the part after the “.”.

                      For example:

                      <property name=“gameMinExposure” type=“float” container=“StaticArray” arraySize=“1”>
                      <value>-12.5</value>

                      If I want to replace “-12.5” with “11” at every found string, it actually comes up like this:

                      <property name=“gameMinExposure” type=“float” container=“StaticArray” arraySize=“1”>
                      <value>-12.11.5</value>

                      Using:
                      Find: (?s-i)(gameMinExposure.+?)-*\d+(</value>)
                      Replace With: ($1)11.5($2)

                      1 Reply Last reply Reply Quote 0
                      • Terry RT
                        Terry R
                        last edited by Terry R

                        @Chuny_OK said in *Help* How to change multiple unknown text string with just one?:

                        If I want to replace “-12.5” with “11” at every found string, it actually comes up like this:

                        OK, some more changes required then. The latest revision of the Find What regex is:
                        (?s-i)(gameMinExposure.+?<value>).+?(</value>)
                        So in this instance I’ve put the 2 tags (<value> and </value>) around the “other” characters (number) that we need to replace. So the .+? does not care what currently exists in this position, but whatever is there will be replaced with the new number which you have in the Replace With field.

                        Terry

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