Search code examples
regexnotepad++

Regex/Notepad++ to extract text from file


I have multiple files with text in parenthesis that I need to extract from the file (or delete everything else in that file). I have a method that works, but it only works for one file. Here is an example of the kind of files I'm dealing with.

(is it on?)
[3.87595  3.87595 0 ]xsh
grestore
NDTMRY+Helvetica[8.5 0 0 -8.5 0 0 ]msf
 mo
(NO) 

The method I have used is as follows:

  1. in notepad++ under the mark tab in find replace; Find: ^(.*?$ (with bookmark line checked)
  2. Search>bookmarks>remove unbookmarked lines

Is there a way/better way to do this for multiple files at a time? In this or another language such as python.

Thanks!


Solution

  • Yes, it is possible to remove in multiple files lines that do not start with (.

    Here is the screenshot with settings:

    enter image description here

    So, here are the instructions:

    1. Press Ctrl+H and click Find in Files
    2. In Find What, type ^(?!\().*\R*, keep Replace With empty
    3. Add file masks in Filters
    4. Select the initial directory in Directory.
    5. Make sure Regular expression radio button is selected.

    Adjust other options and hit Replace in Files button.