4

I have some text I want to edit using Notepad++.

The text follows a pattern such as test 1 - test1, test 2 - test2, test 3 - test3 and so on, one per line. I would like to 'cut' all the characters on every line after the '-' character/symbol. I need everything that has been cut to be put in clipboard so i can paste it elsewhere. (If the prefix can not be put in the clipboard, then simply how to delete all characters after the '- ' would suffice).

By search\replace in notepad using -.* will remove everything after the '-'. I need to know how to cut and copy it rather. If I can figure out how to remove everything BEFORE the '-', like the above does, I can just copy it all. Any ideas? Would be much easier.

2
  • Please explain the down vote of this question? It's an issue I have and need an answer to. It does not exist anywhere on the site, and it's asked straight forward. Aug 29, 2013 at 1:20
  • It was mostly wording and formatting issues. The edited question is fine, so I removed my downvote. Aug 29, 2013 at 2:52

4 Answers 4

5

To get the prefixes (the text before the dashes), press Ctrl+H and fill out the fields as follows:

enter image description here

To get the suffixes (the text after the dashes), press Ctrl+H and fill out the fields as follows:

enter image description here

This breaks if there are any dashes in either the prefix or the suffix.

If you need to get both separately, just capture the results from the first replace to a different file (or the clipboard), then press Ctrl+z and perform the second replace.

If you need to include the dash and/or spaces, you can add them as needed in the "Replace with :" text box before or after the replacement placeholder.

1
  • +1 helped me remove comments out of an SQL file. saved me hours of manual finding and deleting. awesome.
    – jmcg
    Dec 18, 2015 at 3:41
3

This is not exactly what you're looking for since it does not use Notepad++, but if you're open to using MS Excel, it'll help with getting what you need on the clipboard in one go.

Open the file in MS Excel and follow the procedure below:

  1. Choose the option 'Delimited' enter image description here

  2. Set the delimiter as - enter image description here

  3. Click 'Finish' and you're done! enter image description here

1
  • Creative, but off-topic for the question, since this pertains to Notepad++. Aug 29, 2013 at 3:08
2

To remove everything before - and the symbol itself use the regexp [^\-\n\r]+- (non-dashes and linebreaks followed by dash).

Replace found text by empty string and select what is left.

-1

Just use block select mode in Notepad++! Hold Alt and highlight text in a block.

3
  • I tried that nothing happened for me. Aug 29, 2013 at 1:25
  • Ok I see what you mean. thats a nice trick actually. But Not all of my lines are the same length so it wont work. Aug 29, 2013 at 1:26
  • It will, just select a block around all the text, it won't add extra spaces. :) EDIT: Sorry, I thought you meant you had just a list like the test you showed, it would work if they started inline and finished at different places.
    – abc_harold
    Aug 29, 2013 at 1:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.