Staredit Network > Forums > Technology & Computers > Topic: Notepad++ Replace
Notepad++ Replace
Dec 8 2011, 6:27 pm
By: IAGG  

Dec 8 2011, 6:27 pm IAGG Post #1



Simple question. How do you Remove any text after and including* the symbol @ on Notepad++?

100@S5
100@S6
100@S7
101@S8

I have thousands of these to remove to leave the numbers before. Thanks in advance.



None.

Dec 8 2011, 7:47 pm NudeRaider Post #2

We can't explain the universe, just describe it; and we don't know whether our theories are true, we just know they're not wrong. >Harald Lesch

can't you replace @?? with [blank]?




Dec 8 2011, 8:03 pm IAGG Post #3



yeah but that wont remove all the random text after the @ as well



None.

Dec 8 2011, 8:17 pm Lanthanide Post #4



Regular expressions?

Also try the TextFX search/replace under the Quick menu I believe it is, this one works a little different from the standard search/replace so you may get better results.



None.

Dec 9 2011, 3:53 am EzDay281 Post #5



I'd go with the "regular expressions" thing as the best suggestion; personally, I'm too lazy to learn them, and believe that (depending on what the exact text you're dealing with is - more rather, how it's formatted), macros would also be quite useful.



None.

Dec 9 2011, 4:34 am CecilSunkure Post #6



I can write you a C program to do it for you if you like. PM if you want me to.



None.

Dec 9 2011, 9:10 am The Starport Post #7



Record a macro:
  1. Before recording, do a find for @ once such that you can press F3 to find again.
  2. Begin recording. Don't press any other buttons until finished.
  3. Enter the following keys: F3, Enter, Down, Left, Ctrl+Shift+Backspace, Backspace
  4. Stop recording.
  5. Select 'Run a Macro multiple times...' and for the current macro simply run it until end of file is reached.

Be sure to test it out, first.



None.

Dec 9 2011, 11:06 am Lanthanide Post #8



Woah you guys, way way over the top. Regular expressions are all you need, and Notepad++ can do it easily. When I posted my reply I was at work where we have Ubuntu so didn't have Notepad++ and wasn't interested in trying to install it or anything (since our ubuntu desktops are set up with better programs anyway).

Using the sample of 4 lines provided, this regular expression works:
Search: (.*)@.*
Replace: \1

Breaking it down: find 0 or more any characters and call this section 1, then find the @ symbol followed by 0 or more any characters. Replace this segment with the contents of section 1. This logic effectively splits the string into 2 parts based on the first @ symbol it finds and throws the second part away.

To use this, click Search menu then Replace (or press ctrl + H). Click on Regular Expression radio button on the bottom left under Search Mode.

Here are some references for the various search/replace tools in Notepad++:
http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Searching_And_Replacing
http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Replacing_Newlines
http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Regular_Expressions

Note that Notepad++ actually doesn't support the full set of regular expression operations and the syntax is slightly different from other tools. It also has rather poor handling of new line characters in general - only Extended mode can find search strings that include new lines, but then you can't use the regular expressions in the replace string. Just tried out the TextFX and that seems to handle new lines much better - last time I tried (probably about a year ago) I couldn't get it to find and replace a newline using regular expressions anywhere, so I guess I've got a newer version of Notepad++ now or something.

Post has been edited 2 time(s), last time on Dec 9 2011, 11:17 am by Lanthanide.



None.

Dec 9 2011, 7:41 pm Heinermann Post #9

SDE, BWAPI owner, hacker.

Search -> Replace...

Then under Search Mode select Regular Expression.


Type
Quote from Find what :
@.*
Quote from Replace with :

then click Replace All. Done.




Dec 9 2011, 7:44 pm EzDay281 Post #10



Quote
Woah you guys, way way over the top.
But still simple enough not to be a problem.
Depending on how much he does anything with his computer, "learn regular expressions" could easily be more over-the-top than "use this entirely self-explanatory tool that takes five seconds to setup".

Granted, most people who use Notepad++ use computers enough that they should learn regex, and nowadays most with access to computers at all are also above that threshold, but... uh, did I have a point? Oh well, whatever.



None.

Dec 9 2011, 7:47 pm Lanthanide Post #11



Cecil was going to write a c program to do it. Tux's macro solution takes longer and is more error prone. In this case the regular expression really isn't anything complicated.

@Heinermann - duh, don't know why I didn't think of that :/



None.

Dec 9 2011, 10:17 pm The Starport Post #12



Quote
Tux's macro solution takes longer and is more error prone.
Not more than regex if you know what you're doing, and arguably just as valuable to learn.



None.

Dec 9 2011, 10:59 pm Lanthanide Post #13



So you think you can record that macro and then run it enough times to replace all instances faster than Heinermann can enter his regex and click "replace all"?



None.

Dec 10 2011, 4:28 am The Starport Post #14



Comparably close. It's not the ideal tool problems like these, but I'm used to using it more than regex, so it's fine for me. Though if I do need serious use of macros I often resort to a separate, dedicated application.

And yes, I've used regex with macros in the past.



None.

Dec 10 2011, 12:56 pm EzDay281 Post #15



Quote
Cecil was going to write a c program to do it.
Well, writing simple programs is just fun. :P
Quote
Tux's macro solution takes longer and is more error prone.
Well, again, my point was that a. "takes longer" is pretty insignificant in this case, and b. yes, "takes longer" if you already know regex, which IAGG presumably doesn't - if you include "time it takes to wait for someone to post the regex on a forum", or "time it takes to read a 5+ page tutorial on an unfamiliar language", then no, the macro solution may be many times faster.



None.

Dec 11 2011, 5:34 am IAGG Post #16



Thanks. Worked perfectly!



None.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[01:19 pm]
Vrael -- IM GONNA MANUFACTURE SOME SPORTBALL EQUIPMENT WHERE THE SUN DONT SHINE BOY
[01:35 am]
Ultraviolet -- Vrael
Vrael shouted: NEED SOME SPORTBALL> WE GOT YOUR SPORTBALL EQUIPMENT MANUFACTURING
Gonna put deez sportballs in your mouth
[2024-5-01. : 1:24 pm]
Vrael -- NEED SOME SPORTBALL> WE GOT YOUR SPORTBALL EQUIPMENT MANUFACTURING
[2024-4-30. : 5:08 pm]
Oh_Man -- https://youtu.be/lGxUOgfmUCQ
[2024-4-30. : 7:43 am]
NudeRaider -- Vrael
Vrael shouted: if you're gonna link that shit at least link some quality shit: https://www.youtube.com/watch?v=uUV3KvnvT-w
Yeah I'm not a big fan of Westernhagen either, Fanta vier much better! But they didn't drop the lyrics that fit the situation. Farty: Ich bin wieder hier; nobody: in meinem Revier; Me: war nie wirklich weg
[2024-4-29. : 6:36 pm]
RIVE -- Nah, I'm still on Orange Box.
[2024-4-29. : 4:36 pm]
Oh_Man -- anyone play Outside the Box yet? it was a fun time
[2024-4-29. : 12:52 pm]
Vrael -- if you're gonna link that shit at least link some quality shit: https://www.youtube.com/watch?v=uUV3KvnvT-w
[2024-4-29. : 11:17 am]
Zycorax -- :wob:
[2024-4-27. : 9:38 pm]
NudeRaider -- Ultraviolet
Ultraviolet shouted: NudeRaider sing it brother
trust me, you don't wanna hear that. I defer that to the pros.
Please log in to shout.


Members Online: jjf28