Need help with replacing/editing lines!
-
Hello everyone, desperately need some help with replacing lines.
My work requires me to occasionally use Notepad++, but only the simple “find & replace” up till now, never the regex ones. So I am not sure whether it is possible to achieve what I intend to do. Anyway, here are my data:There are two things I am hoping to do with it:
-
to change all the individual “0” into “0.000”. So the 2nd (and 18th, 22th, 24th, 25th etc.) line should become 0.000, but other lines should stay the same, like the 6th line should still be “0.006”.
-
to replace all the lines contains “e-XX” to “0.000”.
For example, the 3-5 line should all become “0.000”.
Don’t know this would make things easier or not but: all these lines that contain “e-XX” have the same length (9 characters).
About my data file though, there are few hundred files like this one, and all have the same number of lines, around 193000.
Here is a part of it:19760101
0
1.974e-05
3.949e-06
2.764e-05
0.006
0.001
0.001
0.000
0.000
0.000
0.000
0.001
0.002
0.001
0.001
0.000
0
0.011
0.071
0.002
0
9.969e-05
0
0
0
0
0.000
0
0
0
0
0.000
0.003
0.002
0.002
6.319e-05
0
0.000
6.319e-05
0.000
0
0
0
0Please help me out, thanks a TON!
-
-
Hello, @moking-c and All,
-
Open the Replace dialog (
Ctrl + H
)-
SEARCH
(?-is)^0$|^.+e-.+
-
REPLACE
0.000
-
Tick the
Wrap around
option -
Select the
Regular expression
search mode -
Click once, on the
Replace All
button
-
-
Close the Replace dialog (
ESC
)
Voila !
In order to verify, you may use, first, the
Replace
button, a few times, before clicking on theReplace All
button !Best Regards,
guy038
-
-
@guy038 Wow, thank you so much for the help! I tried and it works perfectly.
-
@guy038 Could you please kindly explain this: (?-is)^0$|^.+e-.+
I understand it contains several parts but have no idea of their meanings.
I want to understand it so I can hopefully modify it in the future in case some similar problem came up. -
Hi, @moking-c and All,
You’re right about wanting a full insight of the solution. Hopefully, this regex is not very difficult to understand :
-
The
^0$
part searches for a single0
between beginning of line (^
) and end ($
) of current line -
The
^.+e-.+
part searches, from beginning of line (^
), for any non-null text, followed with the stringe-
, with this exact case, and followed with any non-null text ,again, till the end of line -
At beginning, the part
(?-is)
part are in-line modifiers which mean :-
Any regex
.
symbol refer to a single standard character ( NotEOL
ones ) : modifier-s
-
Any search is sensible to case : modifier
-i
( not insensible ! )
-
For further learning about regexes, see :
-
The official N++ documentation : https://npp-user-manual.org/docs/searching/#regular-expressions
-
The Regex FAQ : https://community.notepad-plus-plus.org/topic/15765/faq-desk-where-to-find-regular-expressions-regex-documentation
Best Regards,
guy038
-
-
@guy038 Can’t say I 100% understood but thank you. Have a nice day :)
-
@moking-c said in Need help with replacing/editing lines!:
Can’t say I 100% understood
I might say things differently from Guy – does it help any with understanding?:
-
Instead of
non-null text
I would say “one or more characters”. -
Instead of
Any regex . symbol refer to a single standard character ( Not EOL ones )
I would say “any.
in the expression can match any character except line-ending characters (carriage return or linefeed)” -
Instead of
Any search is sensible to case : modifier -i ( not insensible ! )
I would say “-i
means to not (from the minus) ignore (from thei
) case of the characters, thus case (of thee
) is relevant”
I don’t know if helps, but it is another way of saying these things.
-
-
@alan-kilborn thank you it helps ;)