Community
    • Login

    Replace tab spaces only inside quotations.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 398 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.
    • UHAX The GreyU
      UHAX The Grey
      last edited by

      Hi all,

      I am quite stuck on this

      I have the following as an example

      Bit1 “Bit2 Bit3 Bit4 Bit5”

      I want to replace the tab in between Bit2, Bit3, Bit4 etc with a space, but leave the tab after Bit1, in short replace all tab chars inside quotations with a space.

      How can this be done, the file I have as over 40,000 lines like the example above so doing it by hand is not possible.

      Regards,

      1 Reply Last reply Reply Quote 0
      • CoisesC
        Coises
        last edited by

        Try this:

        From the main menu, select Search | Replace…; then fill in:

        Find what: \t(?=[^\r\n"]*+"[^\r\n"]*+[\r\n])
        Replace with: (a single space)
        Search Mode: Regular expression

        then click Replace All.

        This assumes that each line in your text either has no double quote marks or has two double quote marks. If there are other cases (such as lines with two quoted strings, or quoted strings that span lines) this will not work.

        UHAX The GreyU 1 Reply Last reply Reply Quote 1
        • UHAX The GreyU
          UHAX The Grey @Coises
          last edited by

          @Coises That worked, thank you!

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

            Hello, @uhax-the-grey, @coises and All,

            Your solution, @coises, seems to work only if :

            • A single "......" section exists in current line

            • Line-ending char(s) end(s) the current line


            @uhax-the-grey, the difficulty to achive that general goal is that the ending char of a section is the SAME char than its beginning char ( the " character ) :-((

            So I propose to split the problem in 3 successive steps :

            • First, we change any couple of " chars, of a single section, with two different control chars ( \x02 and \x03 )

            • Secondly, we use the generic regex mechanism, described here, to replace any \t character by a space char, in "............" sections only

            • Finally, we restore the two original " delimiters for each section


            This method leads to the 3 successive regex S/R below :

            SEARCH (?s)"(.*?)"

            REPLACE \x02\1\x03

            Then :

            SEARCH (?:\x02|(?!\A)\G)(?s:(?!\x03).)*?\K\t

            REPLACE \x20

            Remark : Do not forget to move the caret ( cursor ) at the very beginning of the current file, before running this second S/R !

            Finally :

            SEARCH [\x02\x03]

            REPLACE "


            Whatever the position of the TAB chars and the " deleimiters, thoughout the text contents, this method should always work properly !

            Best Regards,

            guy038

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