Find and replace
-
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? -
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 buttonWhat 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
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 10this 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
andWrap around
ACTION Click once on the
Replace All
button, or several times on theReplace
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 group1
-
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 textABC
, 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
-
-
@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! -
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,