How to copy marked text in notepad++

Viewed 149564

I have a part of HTML source file that contains strings that I want to select and copy at once, using the regex functionality of Notepad++.

Here is a part of the text source:

<option value="Performance"
>Performance</option>
<option value="Maintenance"
>Maintenance</option>
<option value="System Stability"
>System Stability</option>

I'm using the regex "[0-9a-zA-Z ]*" to search the "value" values. I have also selected the feature in Notepad++ search to highlight/mark the found text. This working fine I now want to copy or cut only the highlighted text to clipboard for further processing. But I'm not able to find this functionality in Notepad++. Is this simply not possible or am I too dumb?

10 Answers

Try this instead:

First, fix the line ending problem: (Notepad++ doesn't allow multi-line regular expressions)

Search [Extended Mode]: \r\n> (Or your own system's line endings)

Replace: >

then

Search [Regex Mode]: <option[^>]+value="([^"]+)"[^>]*>.*

(if you want all occurences of value rather than just the options, simple remove the leading option)

Replace: \1

Explanation of the second regular expression:

<option[^>]+     Find a < followed by "option" followed by 
                 at least one character which is not a >

value="          Find the string value="

([^"]+)          Find one or more characters which are not a " and save them
                 to group \1

"[^>]*>.*        Find a " followed by zero or more non-'>' characters
                 followed by a > followed by zero or more characters.

Yes, it's parsing HTML with a regex -- these warnings apply -- check the output carefully.

This is similar to https://superuser.com/questions/477628/export-all-regular-expression-matches-in-textpad-or-notepad-as-a-list.

I hope you are trying to extract :
"Performance"
"Maintenance"
"System Stability"

Here is the way - Step 1/3: Open Search->Find->Replace Tab , select Regular Expression Radio button. Enter in Find what : (\"[a-zA-Z0-9\s]+\") and in Replace with : \n\1 and click Replace All buttton. Before Clicking Replace All

Step 2/3: After first step your keywords will be in next lines.(as shown in next image). Now go to Mark tab and enter the same regex expression in Find what: Field. Put check mark on Bookmark Line. Then Click Mark All. Bookmark the lines

Step 3/3 : Goto Search -> Bookmarks -> Remove unmarked lines.Remove Unmarked lines

So you have the final result as belowFinal Result

It would be a great feature to have in Notepad++. I use the following technique to extract all the matches out of a file:

powershell
select-string -Path input.txt -Pattern "[0-9a-zA-Z ]*" -AllMatches | % { $_.Matches } | select-object Value > output.txt

And if you'd like only the distinct matches in a sorted list:

powershell
select-string -Path input.txt -Pattern "[0-9a-zA-Z ]" -AllMatches | % { $_.Matches } | select-object Value -unique | sort-object Value > output.txt

"Copy Marked Text" is now a Built-in function in Notepad++ – Illustrated answer

My installed version of Notepad++ was a few years old, and I had turned off auto updates. After updating Notepad++ to the latest version (8.1.1), I found out that copying marked text is indeed a supported function nowadays!

I take the liberty of making this an answer of it's own, even though there are comments above trying to explain the same thing. In this way I'm able to illustrate with a picture:

enter image description here

A lengthier way for the same result would be to "Mark all", and go to the menu "Search". Then select "Copy styled text / Find style (marked)".

No, as of Notepad++ 5.6.2, this doesn't seem to be possible. Although column selection (Alt+Selection) is possible, multiple selections are obviously not implemented and thus also not supported by the search function.

In Notepad++ v7.9.3 they provide option to copy marked text. Go to Search menu and select mark option..(Ctrl+M) Enter what you want to find and click mark all option then click on copy marked text and paste wherever you want.

You can copy multiple mark lines using regular expression option in search mode.

A simple example : let’s suppose that you are looking for the litteral string 12345, anywhere, on a line.

First, to match all the contents of that specific line, as well as its End of Line characters, just use the regex : ^.*12345.*\R

Secondly, to select : All the contents of that line and the next 10 lines, use the regex : ^.*12345.*\R(.*\R){10}

All the contents of that line and the previous 10 lines, use the regex : (.*\R){10}^.*12345.*\R

All the contents of that line and the 5 lines, before and after this line, use the regex : (.*\R){5}^.*12345.*\R(.*\R){5}

Note : For the third example, another syntax, that uses a subroutine call, to the group 1, (?1), is possible : (.*\R){5}^.*12345.*\R(?1){5}

I had the same problem. You can list the regex matches in a new tab, every match in new line in PSPad Editor, which is very similar as Notepad++.

Hit Ctrl + F to search, check the regexp opion, put the regexp and click on List.

Related