Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Textpad or Notepad++ is there an option to export all the matches for a regular expression find, as a single list?

In a big text file, I am searching for tags (words enclosed in % %), using regular expression %\< and \>%, and want all the matches as a single list, so that I can remove duplicates using Excel and get a list of unique tags.

share|improve this question
up vote 25 down vote accepted

You can achieve this by using Backreferences and Find and Mark functionality in Notepad++.

  1. Find the matches using regex (say %(.*?)% ) and replace it by \n%\1%\n , after this we will have our target word in separate lines (i.e. no line will have more than one matched word)

  2. Use the Search-->Find-->Mark functionality to mark each line with regex %(.*?)% and remember to tick 'Bookmark Line' before marking the text

  3. Select Search-->Bookmark-->Remove Unmarked Lines
  4. Save the remaining text. It is the required list.
share|improve this answer
worked perfectly! thanks Lamb – Kiranshell Sep 21 '12 at 19:11
I have one more file with <> as tags instead of % %, I tried with <(.*?)> and \n<\1>\n, but its not working, please help. – Kiranshell Sep 21 '12 at 19:27
you are welcome :) For me its working for <> also. Are there Nested <> ? Could you elaborate what exactly is 'not working' ? – Ankit Mishra Sep 22 '12 at 16:18
I am trying to make a list of tags like before but these once have <>, I am using <(.*?)> instead of %(.*?)% and \n<\1>\n instead of \n%\1%\n, this is the link to a sample file – Kiranshell Sep 22 '12 at 19:17
I tried it again with the provided text and using <(.*?)>, its working normally. I got the list of tags <Supplies> <hostname>.....and so on – Ankit Mishra Sep 22 '12 at 19:45

Is doing this in Notepad++ a mandatory requirement?  Are you on Windows or some form of Unix?  If you’re on Windows, you can do it (partly) from the Command Prompt:

findstr /r "%[a-z].*[a-z]% %[a-z]%" your_file > new_file

findstr is vaguely inspired by grep, so this new_file will contain all lines matching your search criteria; you can then use Notepad++ to strip out the unwanted text (to the left of the first % and to the right of the second one).

And, of course, if you’re on Unix, you can do the equivalent task with sed.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .