Find and replace

  • Hi can any one help-me with this sentence?
    i have this text:

    and i need to change to:
    how can i do it?

  • @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…

  • Ok tks.

  • 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
    |H010|000009|UND1|2|6,78|13,56|0|||1|6,78| for this

    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?

  • 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,]*


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



  • @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!

  • @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.

  • this was so great. tks guy038,

Log in to reply