Community
    • Login

    Find and replace

    Scheduled Pinned Locked Moved General Discussion
    8 Posts 4 Posters 2.4k 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.
    • Léo CostaL
      Léo Costa
      last edited by

      Hi can any one help-me with this sentence?
      i have this text:
      |C175|5102|15|0|01|15|1,65|||0,25|01|15|7,6|||1,14|||
      |C175|5405|3,5|0|01|3,5|1,65|||0,06|01|3,5|7,6|||0,27|||
      |C175|5656|36|0|01|36|1,65|||0,6|01|36|7,6|||2,73|||

      and i need to change to:
      |C175|5102|15|0|01|15|1,65|||0,25|01|15|7,6|||1,14|311011||
      |C175|5405|3,5|0|01|3,5|1,65|||0,06|01|3,5|7,6|||0,27|311011||
      |C175|5656|36|0|01|36|1,65|||0,6|01|36|7,6|||2,73|311011||
      how can i do it?

      Scott SumnerS 1 Reply Last reply Reply Quote 0
      • Scott SumnerS
        Scott Sumner @Léo Costa
        last edited by

        @Léo-Costa

        Seems like all you are changing is the insertion of 311011 in the same place in each line. Pretty straightforward:

        Find what zone: \Q|||\E$
        Replace with zone: |311011||
        Wrap around checkbox: Ticked
        Search mode: Regular expression
        Action: Press the Replace All button

        What this is doing is looking for three | characters at the end of a line (the $ ties the search to end-of-line). The \Q and the \E are used to remove the special meaning of | because you want those interpreted literally as they occur in your text. That about the extent of the “tricky stuff”. Hope this helps. And maybe read up on regular expressions and how they work…

        1 Reply Last reply Reply Quote 0
        • Léo CostaL
          Léo Costa
          last edited by

          Ok tks.

          1 Reply Last reply Reply Quote 0
          • Léo CostaL
            Léo Costa
            last edited by

            now i have same more difficult i guess: this text above:

            |H010|000009|UND1|2|6,78|13,56|0|1||1|6,78| replace this
            1
            |H010|000009|UND1|2|6,78|13,56|0|||1|6,78| for this

            |H010|000009|UND1|2|6,78|13,56|0|1||1|6,78|
            1 2 3 4 5 6 7 8 9 10

            this is more difficult for me, i dont know if this is possible

            the expression must be count | when count 8 then replace |1| for this ||

            is this it possible?

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

              Hello, @léo-costa,

              Ok, Léo, I understood the problem :-) So, you would like to get the modified text, from the initial one , like below :

              N° of the | Symbol      1    2      3    4 5    6     7 8 90 1    2
              INITIAL text  :         |H010|000009|UND1|2|6,78|13,56|0|1||1|6,78|
              
              MODIFIED text :         |H010|000009|UND1|2|6,78|13,56|0|||1|6,78|
              

              If so, you could use the following regex S/R :

              SEARCH ^((\|[\w,]*){7}\|)[\w,]*

              REPLACE \1

              OPTIONS Regular expression and Wrap around

              ACTION Click once on the Replace All button, or several times on the Replace button


              Notes :

              • The ^ assertion represents each beginning of line

              • The literal | symbol will have to be escaped as \|

              • The part [\w,]* stands for any range, even empty, of word characters or comma(s)

              • Then the syntax (\|[\w,]*){7}\| matches 7 times the form |....., followed by a | symbol

              • And, as this syntax is surrounded by parentheses, all the text of each line, till the seventh block |....., as well as the 8th symbol |, is stored as group 1

              • Finally, a last [\w,]* grabs the contents after this 8th |. That is to say, in your example the simple digit 1

              • In replacement, as you want to get rid of this 8th content, we simply rewrite the first seven ones ( group 1)


              Remark :

              For changing the contents, after the nth symbol |, by, for instance, the text ABC, the syntax of this regex becomes :

              SEARCH ^((\|[\w,]*){n-1}\|)[\w,]*

              REPLACE \1ABC

              And, of course, you must replace the n-1 expression, between the curly braces, with a real integer value !

              Cheers,

              guy038

              1 Reply Last reply Reply Quote 1
              • Chip CooperC
                Chip Cooper
                last edited by

                @guy038 @Léo-Costa
                I’d like to understand what it meant by, and how to use ‘regex’ in Np++. I’ve seen this used in other posts, and it looks really useful. Could you, anyone direct me to where I could learn about this? Thanks!

                Scott SumnerS 1 Reply Last reply Reply Quote 0
                • Scott SumnerS
                  Scott Sumner @Chip Cooper
                  last edited by

                  @Chip-Cooper

                  This thread contains a posting by @guy038 that discusses basic references on Regular Expressions. Look for the text For noob people, about regular expressions concept and syntax.

                  1 Reply Last reply Reply Quote 0
                  • Léo CostaL
                    Léo Costa
                    last edited by

                    this was so great. tks 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