IntelliJ/PyCharm 18 find with regex and save result to text file

You can do a search in IntelliJ/PyCharm by using regular expression and get the results into a text file. This is extremely useful if you want to extract information like warnings, errors or messages. The example below is tested on IntelliJ/PyCharm community 2018.1

Let say that you have the following code template for errors in your project:

```python
error1 = 'not found'
error2 = 'wrong format'
...
error555 = 'duplicated value'
```

all of them raised in different parts of your project and different methods. In order to extract all messages like this you can do:

  1. Press CTRL+SHIFT+F
  2. Enter search text
    error\d =
  3. Enable Regex ?
  4. Press Open in Find Window
  5. Press button Export to a Text File - ALT+O
  6. Give name to the export file - report.txt and check the folder
  7. Save

Button Export to a Text File could be hidden at the bottom of the sidebar so in order to make it visible:

  • increase Find Window length until you see all buttons or
  • click to button >> to show the hidden buttons

Example output:

Targets
    Occurrences of 'error\d = ' in Project
Found Occurrences  (169 usages found)
    Unclassified occurrence  (98 usages found)
        projectX  (98 usages found)
            packageX  (45 usages found)
                methodX.py  (35 usages found)

This is the official description of the button:

Save the contents of the current result tab. In the Export preview dialog, specify the target file or copy information to the clipboard. Before saving, you can also modify the information to be saved. 

You can see the result of the image below:

Selection_013

Related Article