{"id":530327,"date":"2024-11-28T14:40:19","date_gmt":"2024-11-28T13:40:19","guid":{"rendered":"https:\/\/blog.jetbrains.com\/?post_type=idea&#038;p=530327"},"modified":"2026-01-12T12:24:43","modified_gmt":"2026-01-12T11:24:43","slug":"advanced-code-analysis-in-intellij-idea","status":"publish","type":"idea","link":"https:\/\/blog.jetbrains.com\/zh-hans\/idea\/2024\/11\/advanced-code-analysis-in-intellij-idea","title":{"rendered":"Advanced Code Analysis in IntelliJ IDEA"},"content":{"rendered":"\n<p>This series of blog posts covers several ways that code analysis in IntelliJ IDEA can help you find and fix problems in your code. In the previous posts, we first looked at how the IDE can help you prevent problems while working with code in the editor before moving on to how to resolve problems throughout your entire project using predefined inspections.<\/p>\n\n\n\n<ul>\n<li>Part 1: <a href=\"https:\/\/blog.jetbrains.com\/idea\/2024\/09\/introduction-to-code-analysis-in-intellij-idea\/\">Introduction to Code Analysis in IntelliJ IDEA<\/a><\/li>\n\n\n\n<li>Part 2: <a href=\"https:\/\/blog.jetbrains.com\/idea\/2024\/10\/code-analysis-for-your-projects-with-intellij-idea-and-qodana\/\">Code Analysis for Your Projects With IntelliJ IDEA and Qodana<\/a><\/li>\n<\/ul>\n\n\n\n<p>While the predefined inspections in IntelliJ IDEA and Qodana are very useful, occasionally you might need something different. In this blog post, we will look at how to find specific patterns in your code using IntelliJ IDEA\u2019s various search functions, such as structural search and replace (SSR), as well as how to create custom inspections using either SSR or RegExp.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Find and replace strings<\/h1>\n\n\n\n<p>If you are looking for a specific string in your code, you can use <a href=\"https:\/\/www.jetbrains.com\/help\/idea\/finding-and-replacing-text-in-project.html\" target=\"_blank\" rel=\"noopener\"><em>Find in Files<\/em><\/a> (<em>\u2318\u21e7F<\/em> on macOS \/ <em>Ctrl+Shift+F<\/em> on Windows\/Linux). For example, if you are searching for where an error is thrown, or a log line is written. You can use this option to find text strings. To replace text, use <em>Find and Replace<\/em> (<em>\u2318\u21e7R<\/em> on macOS \/ <em>Ctrl+Shift+R<\/em> on Windows\/Linux).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXfLZ03DHuVw7N7MwOWRK9c0XoZAZRsLaMwiRHnwNjY5pEVCcU5CTAk_ZOe-V0gJrRgZan-BEuE8gZhdWOgG4ggd2MsYUGkWBx1tyq7fPXt_MIlYNm2ch8vSBj6ToeVWTXrVy0LjTg.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Find in Files<\/em><\/figcaption><\/figure>\n\n\n\n<p>You can narrow your search by selecting options such as <em>Words<\/em> or <em>Match case<\/em> to find the exact word in a project or match the letter case. Alternatively, you can use the <em>File mask<\/em> option to narrow your search to a specific file type, for example, Java classes or markdown files.&nbsp;<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Structural search and replace<\/h1>\n\n\n\n<p>To search for more complicated code patterns, you can use <a href=\"https:\/\/www.jetbrains.com\/help\/idea\/structural-search-and-replace.html\" target=\"_blank\" rel=\"noopener\">structural search and replace<\/a>.&nbsp;<\/p>\n\n\n\n<p>Start by opening the <em>Structural Search<\/em> feature via <em>Edit | Find | Search Structurally\u2026<\/em> or by entering it into <em>Search Everywhere<\/em> (<em>\u21e7\u21e7<\/em> on macOS \/ <em>Shift+Shift<\/em><strong> <\/strong>on Windows\/Linux) and finding it there. You can either reuse existing templates or create your own. Below, we will illustrate how each of these methods works.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Reuse existing templates<\/h2>\n\n\n\n<p>When you open <em>Structural Search<\/em>, you\u2019ll see that there are numerous search templates available, and these are grouped by language or type.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXdY48Yrwp3Dleflzle4LpcLig3XckEs3ke49G-30Lhbxr9MtkeLU6wLdx3ACzFM0ZqKweOsyDtsj8qzkw71I6a07VC09OerNcZLXELLtc3vYrJLlkqMGEldYdWmWHJefJ6Lw8L-lg.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Structural Search<\/em><\/figcaption><\/figure>\n\n\n\n<p>You can reuse existing templates and use modifiers to look for what you need.<strong> <\/strong>For example, let\u2019s look for methods or constructors that use more than five parameters, as this could be considered a code smell. The quickest way to do so is to reuse an existing template. As you may know, menus in IntelliJ IDEA are searchable. Select the menu on the left, press <em>Find<\/em> (<em>\u2318F<\/em> on macOS \/ <em>Ctrl+F<\/em> on Windows\/Linux), and search for the template you want. In this case, if you enter the words \u201cconstructor\u201d and \u201cmethod\u201d, you\u2019ll find the existing <em>Constructors &amp; methods<\/em> template. Select this template and change the minimum count value of the method parameters to <em>5<\/em>. Then, run the search by clicking <em>Find<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXczhRY0uCX84j6fneotSQEtuebCZ9guKqBhiblEzlsiKstGJw56SThTzUOQjgLVyypC2xaOJHIpR2O1cPm7GnpPazPk4CLVsxnfwUMMo5K_pAXI53WvjOTqAG7pflccmo_NSpjtNw.gif\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Structural Search<\/em><\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Create your own template<\/h2>\n\n\n\n<p>Alternatively, you can create your own template.<\/p>\n\n\n\n<p>For example, let\u2019s consider the following code:&nbsp;<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">String value = opt.orElse(null);\n\nif (value == null) {\n\n&nbsp;&nbsp;&nbsp;throw new IllegalArgumentException(&quot;Missing value&quot;);\n\n}<\/pre>\n\n\n\n<p>In this example, the <code>null<\/code> check can be integrated into <code>Optional<\/code> using <code>orElseThrow()<\/code>, as follows:<\/p>\n\n\n\n<p><em><code>String value = opt.orElseThrow(() -&gt; new IllegalArgumentException(\"Missing value\"));<\/code><\/em><\/p>\n\n\n\n<p>Rather than finding each occurrence of this pattern in our code base and changing them manually, you can create a custom inspection to do this for you.&nbsp;<\/p>\n\n\n\n<p>Select an occurrence of the code pattern you want to change and open the<em> Structural Search<\/em> window via <em>Search Structurally<\/em>.&nbsp;<\/p>\n\n\n\n<p>When you open <em>Structural Search <\/em>with your chosen code selected, the snippet will be prefilled in the <em>Search Template<\/em> field inside the <em>Draft Template<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXceECxErKlYcuM1ZRSi4cQcJSBb6EIXfMBqgvExji9hAA_0PYJll4le41SzQDK1uDkzfNq24JdwproUyVHEk0mqO50q4wzC4Sgkjexq0ywghNzXDDpY8ztdXx3kH744dcgosT9Y.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Structural Search \u2013 Draft Template<\/em><\/figcaption><\/figure>\n\n\n\n<p>Since you want to replace this code pattern, you can click the <em>Switch to Replace<\/em> button in the top right-hand corner. Alternatively, you can go to <em>Edit | Find | Replace Structurally\u2026<\/em> or use <em>Find Action<\/em> (<em>\u2318\u21e7A<\/em> on macOS \/ <em>Control+Shift+A<\/em><strong> <\/strong>on Windows\/Linux) to open it directly. Then, add the desired pattern to the <em>Replace template<\/em> field in the <em>Structural Replace<\/em> popup.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXe1dMxX5rG72jpVT5Nx2uEYVEI1QmV1OA09_2K51C6Tj1z5-JuqsszqrEbPcXNJhRO0rcG4WiQbB-GWdu_IW4KaGiETHnD-G1m3LKRRbLGiVMsE_4CUxlvCbJRQMiF5pITRxY6P8w.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Structural Replace \u2013 Draft Template<\/em><\/figcaption><\/figure>\n\n\n\n<p>Now, you can define placeholders in the templates and add modifiers where needed. Make sure to match the placeholders from the <em>Search template<\/em> to the corresponding variables in the <em>Replace template<\/em>. In both templates, replace the <code>value<\/code> and <code>opt<\/code> variables with the placeholders <code>$result$<\/code> and <code>$Optional$<\/code>, respectively. With the caret on <code>$Optional$<\/code>, click <em>Add modifier<\/em> in the right-hand pane, select <em>Type<\/em>, and set the <em>Type<\/em> to <code>Optional<\/code>.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXcKygC_felpXgsTHQon2udo7xgCcCG9gtDuLxHypRklSFpvI4ON9wNMDbCvfv2Kc2cXjhIwhuZbe9Ln50kqTgOlBxMv6Fa8qtApaCjO0ZvpnRlK_4S5kHWMCfB18F1t6z7QrqgP.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Add Modifier<\/em><\/figcaption><\/figure>\n\n\n\n<p>The resulting template will look like this:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXcv4AOZL6sJ9VTQ3sEGrZx2IqyRv1y5iQnVhqivN-ASrVwBxjcv4MWkOSMwLB08p2Ga1Rl7T5S9eWrrg5SxQzq-WEt5KAvmXq7qiDerJ_sixn2K2fwrz8VDCqiq5fsQtWIgYwE.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Structural Replace<\/em><\/figcaption><\/figure>\n\n\n\n<p>When you have an example in our code for the template you are creating, you can make sure your template matches the code. IntelliJ IDEA will tell you right away if there are no matches to the specified template in your project.<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXdr-meHKp4NjlCRNIAUoT_TwjjQAOiWLcGPLVnIQqKPiEmoOj1WCxwQZpMgkgioDeNN5EP46fZUxkCzw9K8uXlUnJPBXNnbswxLQtfEm35a9Cd241x9ZiMQAiGoihnu__ogCTot.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>No Matches<\/em><\/figcaption><\/figure>\n\n\n\n<p>Click the <em>Find<\/em> button to find all matches to the specified search pattern in your code.<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXc1WEKhgWVSJ9cQx4WoN_3ftLq4HYfK5mklB37FRCrhqaaSSIzbRBNfHL6OpJUSXKDz4sOmzdN4Hk4d50Bs1EAL-l7cIaePbMwZKHf0e6KsNQptO0Pgc2QIpdEXCVQDvEPxA2WM.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Find Results<\/em><\/figcaption><\/figure>\n\n\n\n<p>In the <em>Find<\/em> results, you can choose to <em>Replace All<\/em> or <em>Replace Selected<\/em> to replace code according to the template you defined. Use <em>Preview Replacement<\/em> to see what the replacement will look like.<\/p>\n\n\n\n<p>Alternatively, you can create an inspection from our template, either by using the <em>Draft Template <\/em>or by clicking <em>Create Inspection from Template&#8230;<\/em> in the <em>Find<\/em> results.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXcXVpsqAl2ZMAV0j7Tg5p2ft7O0o1GTWdORcdsIO6PYcWGFo_8TkQSPFyODkJ11sYrPCizFlqsQdfwQIR7r1OEN0BPVTIyqlPe1RUhdOfnRGDLQBtvNDyumA-vCmP1QYVlReZHpow.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Create Inspection From Template<\/em><\/figcaption><\/figure>\n\n\n\n<p>In the popup, you can fill in the metadata desired for your inspection, including an <em>Inspection name<\/em>, a <em>Description<\/em>, a <em>Problem <\/em>tooltip, and a <em>Suppress ID<\/em>.&nbsp;<\/p>\n\n\n\n<p>Once you click <em>OK<\/em>, you\u2019ll see that the code matching the newly created inspection is highlighted in the editor. Now, when you click <em>Alt+Enter<\/em> on the highlighted code, IntelliJ IDEA will suggest replacing the code according to your template.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXf2VZ6aJT8ygHpW8JshzlRxBxhzSibblP0dgxjBnBNTlPxvnt2rL270LS637Kj-Lkc8VrWmuX5mqeBI4ENUUHzCW3I_x8FKQP9tXrifgE22okpML97FBpZoHQRkDolmcq08C3XWFA.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Replace Code<\/em><\/figcaption><\/figure>\n\n\n\n<p>If you wish to edit your custom inspection further, you can find it in <em>Settings<\/em> under <em>Editor | Inspections<\/em>.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Custom inspections<\/h1>\n\n\n\n<p>As described above, you can create a custom inspection from a <em>search and replace <\/em>template.&nbsp;<\/p>\n\n\n\n<p>If you already know that you want to create a custom inspection, you can go ahead and do this right away.<\/p>\n\n\n\n<p>To create a custom inspection, go to <em>Settings | Editor | Inspections<\/em>, click <em>Add Custom Inspection<\/em> (<em>\u2318N<\/em> on macOS) \/ <em>Alt+Ins<\/em> on Windows\/Linux), and select the type of inspection you want to create. You can use search and replace templates or RegExp to do this.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXeY7wfYA0e4yBKNmiFQ120fC3fPbEmdsdxzdmWlQxDYidlhoNjUcGDKbf5zxpXq_LDzvVtOwo_AUqyXTuXR2evf56R_JQroWV_tA6kRkmnTogCv2eTFH-1XRZsaEceqPsFe4Nj4EA.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Add Custom Inspection<\/em><\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Custom inspections using <em>Structural Search<\/em><\/h2>\n\n\n\n<p>To create an inspection using <em>Structural Search<\/em>, select <em>Add Structural Search Inspection<\/em>. To include a quick-fix in the inspection, select <em>Add Structural Replace Inspection<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXf6ex62laYdMQnLHtt3ouih3mKjSkwEQ7JKjVcbLt_VYlcxEkJmT9ZF_Vqne8VCSIqspC5hdeU_7oXE8YY8BkHA-2kmCqPj2WHcREj8mIfkOeo6LgVXeHFBDyTGm7bQGEGQFWWaw.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Add Structural Search Inspection<\/em><\/figcaption><\/figure>\n\n\n\n<p>For example, you can create an inspection for the example above where you\u2019re looking for methods or constructors that use more than five parameters.<\/p>\n\n\n\n<p>Just as in the previous example, you can use the existing <em>Constructors &amp; methods<\/em> template and modify the minimum count value of the method parameters to <em>5<\/em>. You can change the inspection name and add a tooltip that will show in the editor.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXdlptEh4fMRbV22UorYwlcfrl5irjASDq2tkqpoIIpy1DfCV_NSzEkT4LDC9GBZNkKi1AkA1eyKM0vYizLcKV7bztxqAvijBqoMXhdIVhNhXuTX_D6tzg6bUbk6x_3nwvdGVq7ctA.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Create Inspection<\/em><\/figcaption><\/figure>\n\n\n\n<p>You can also edit the <em>Severity<\/em> and <em>Highlighting in editor <\/em>fields.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXeztz290-IodsJyLEb2pTpWM5kPOKwbC0SzIBSrqELz8kbLxYNWtWmmV7mT_hZ7g68WpgQL-QB-yKzbPUdoHYvCwhCEkatL2l1mYVWDWIUPzhcBYRyf9oQy_I3r1_nx-zdQ49GYGw.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Severity<\/em><\/figcaption><\/figure>\n\n\n\n<p>You can edit or remove your custom inspection via <em>Settings<\/em> at any time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Custom inspections using regular expressions<\/h2>\n\n\n\n<p>Alternatively, you can <a href=\"https:\/\/www.jetbrains.com\/help\/idea\/regex-search-and-replace-inspections.html\" target=\"_blank\" rel=\"noopener\">create inspections using regular expressions<\/a> to search for and replace specific patterns of text.<\/p>\n\n\n\n<p>To create an inspection, open <em>Settings<\/em> and go to <em>Editor | Inspections<\/em>. Under <em>User defined<\/em>, select <em>Regexp<\/em> and click the <em>+<\/em> button on the right-hand side of the screen. Then, select <em>Add RegExp<\/em> <em>Search Inspection\u2026<\/em>.<em><br><\/em><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXfyITtOMWDC9HQf0RAlQshmKmD3wsaNEj-ODFssRqwvi-ismHEGNSVcx6aVdJkaxFyWQdi4-9DWpr_AILjZ14Uzz4BKrjUpOl5D_bn406pFUz7vYigB8tB-3GIFHYP3oIPY1hlwwg.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Add Custom Inspection \u2013 RegExp<\/em><\/figcaption><\/figure>\n\n\n\n<p>You can now create your inspection by typing the regular expression. As this example uses Kotlin, select <em>Language = Kotlin<\/em> from the dropdown menu in the top right of the window.<\/p>\n\n\n\n<p>In this example, let\u2019s look for <code>println()<\/code> methods, as you probably don\u2019t want your debugging statements to end up in production. Since you are using regex, you\u2019ll need to escape the brackets. Search for <code>println(\".*?\")<\/code> to find any <code>println()<\/code> method with an argument.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXcXGhtKgC-SqisAzlOYa0z6Bax-U1n9zNS9kthLgxG565u-WgP0bF2fhfvL6vlqy8_LdJmsmLSwpboen-p0vuaMtpPsNAhU1y5DF7gBFZ9OLX5-tVydzMDIXED1XdFjc5OXShMxuA.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Create Custom Inspection \u2013 Regex<\/em><\/figcaption><\/figure>\n\n\n\n<p>Click <em>OK<\/em> to go to the <em>User Defined Inspection in \u2018Default\u2019<\/em> popup and fill in the details for the inspection. For example, you can enter \u201cprintln\u201d in the <em>Inspection name <\/em>field, \u201cSpot all println in the code\u201d under <em>Description<\/em>, and \u201cSpotted: #ref\u201d in the <em>Problem <\/em>tooltip, where <code>#ref<\/code> will refer to the code in which <code>println<\/code> has been found. Finally, enter \u201cPRINTLN\u201d under <em>Suppress ID <\/em>and click <em>OK<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXdQ8KNI0xldkwd7OxOKtihipre6ZZGd9RqSFWgXgx5RGbGpiW0kT6sm3-iA44PdThbkBKnFkdPiHJE0ioHWbyGfoHCJvgLtkXmf2nxjWjeoRIUq3M9ZkkFHVj2DNZ_AxTXM0ufJhQ.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>User Defined Inspection<\/em><\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXdXy8cLBnMOVem-OwcDz0dgZRz0nhMwPc_Tq-LQPSu2mAgFJ9eoRkDDDyB8ZCWqmvLu21N7wILXQ3coAQWSVVGGRi8Th6bOfsf__qjGQxXvM2lzxLyfQa7o4_L2gb06wlo0hQfL.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Custom Inspection \u2013 Regex<\/em><\/figcaption><\/figure>\n\n\n\n<p>You will now see the created custom inspection under <em>User defined | RegExp<\/em> with an exclamation mark, as the current <em>Severity<\/em> value is <em>Warning<\/em>. You can change the severity level as well as how this inspection will be highlighted in the editor in the panel on the right-hand side of the screen.<\/p>\n\n\n\n<p>Now, any code that meets this inspection will be highlighted in the editor. You might also want to add a quick-fix to the inspection. To do so, you\u2019ll need to edit the inspection you just defined.&nbsp;<\/p>\n\n\n\n<p>In <em>Settings, <\/em>go to<em> Editor | Inspections<\/em>, select the <em>RegExp <\/em>pattern in the bottom right-hand corner of the <em>Settings<\/em> screen, and click the <em>Edit <\/em>button.<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXcpno8_gW4jDvVqkinO5R4Wvjv3FUUJUVMGCXM4syTWxaW7-MiMrmblsAc91l2ptKtUKNIP5Jg-92MV77FzXm-2jMkXEfwYYaDP-zlz6SuOTfJdoPSo1ROWvdLMtGZRr7Bax3b1pw.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Edit RegExp Inspection<\/em><\/figcaption><\/figure>\n\n\n\n<p>In the <em>RegExp<\/em> popup that opens, click the <em>Enable Replace<\/em> button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"3840\" height=\"2160\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/11\/Enable-Replace.png\" alt=\"\" class=\"wp-image-530333\"\/><figcaption class=\"wp-element-caption\"><em>Enable Replace<\/em><\/figcaption><\/figure>\n\n\n\n<p>In the <em>Replacement<\/em> field, you can enter any code you like. For example, you might decide to add <code>\/\/<\/code> to comment out the code.<\/p>\n\n\n\n<p>In order to refer to the code you want to replace, you\u2019ll need to capture the entire piece of code that you want to use in the <em>Replacement<\/em> field. You can do so by wrapping the code with brackets as follows: <code>(println(\".*?\"))<\/code>. This will now be your first regex group, and you can refer to it in the <em>Replacement<\/em> field as <code>$1<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXeCFGnZSZ3xRZFLpUSJI9N-fAJvcrf1G1Pd7X73GNMhTktTp87e2KJkO6uIIqf2iLlOxzDiuEXdUL61rQNfXGHVQ6_q6um6tiGxzPoe6bi1cA3piVY-XXTesdQ430tJQ72hqvuROw.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Replace RegExp<\/em><\/figcaption><\/figure>\n\n\n\n<p>Now, when you press <em>Alt+Enter<\/em> on the highlighted code, you\u2019ll be given the option to replace the code according to your RegExp template.<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXc214jGUEZL9Ej9A6uM6ouKbaKV_4EhokoB2XDhqYfgy-SHaMNp5ryFCwJXFCJpwwnF0Cj-3xtI1XjlKROnO5XUPnRErFB_g2Q8zIIs348FT0c4hqkd0VCRWBlRtRK7mNGLviMriA.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Replace<\/em><\/figcaption><\/figure>\n\n\n\n<p>If you don\u2019t want to replace the code according to the quick-fix, you can also suppress this inspection. Click the kebab menu (three dots) to the right-hand side of the inspection (or press the right arrow key), and select one of the<em> Suppress <\/em>options from the menu to suppress this inspection for the current file, method, or statement.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXfPuMFpEy2AydQMXDtlQURZ9m6MpkWFu5SzOdpGxYXDg__Y3cWcONapKPnadGr-6-q9oCo1XbXLigCIiksjYMi62Ohu0HNXHLEv0uMcYzP2uqlm0yiSBndmB_Gl-qpcpGfYa-zWHA.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Suppress<\/em><\/figcaption><\/figure>\n\n\n\n<p>Selecting this option will add a <code>@Suppress<\/code> statement to the file.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/09\/AD_4nXfJYnv6QiZXpI80nV2uELDH8uDT_cbyw4cRCVzMFCR3HMqiZXQJQSchVZ2yA-yZ2BDD2MxmlpdnA_AEjrIGidVgzaYWygYmrKbbtaLHre8nTFcc55W0Os5ij5xtA7gHwEqxcV8CEw.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><em>Suppress Statement<\/em><\/figcaption><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">Conclusion<\/h1>\n\n\n\n<p>While IntelliJ IDEA comes with a large set of useful inspections, sometimes you may want to look for something specific in your project. You can search for specific strings or use <em>Structural Search<\/em> to look for patterns in your code that cannot be captured by a text string. You can also create custom inspections using either <em>Structural Search<\/em> or <em>RegExp<\/em> and even choose to define quick-fixes for them if you wish. This functionality makes improving your code base quicker and easier.<br><\/p>\n\n\n\n<p>In the previous posts of this series, we looked at <a href=\"https:\/\/blog.jetbrains.com\/idea\/2024\/09\/introduction-to-code-analysis-in-intellij-idea\/\">how to use inspections in the editor<\/a> and <a href=\"https:\/\/blog.jetbrains.com\/idea\/2024\/10\/code-analysis-for-your-projects-with-intellij-idea-and-qodana\/\">how to run inspections on our project<\/a> with <a href=\"https:\/\/www.jetbrains.com\/qodana\/\" target=\"_blank\" rel=\"noopener\">JetBrains Qodana<\/a>. We hope you have enjoyed this series and hopefully learned something new. Please let us know in the comments!<\/p>\n","protected":false},"author":1342,"featured_media":531001,"comment_status":"closed","ping_status":"closed","template":"","categories":[4759,5088,4113,2347],"tags":[991,40],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/idea\/530327"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/idea"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/types\/idea"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/users\/1342"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/comments?post=530327"}],"version-history":[{"count":9,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/idea\/530327\/revisions"}],"predecessor-version":[{"id":673163,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/idea\/530327\/revisions\/673163"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/media\/531001"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/media?parent=530327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/categories?post=530327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/tags?post=530327"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/cross-post-tag?post=530327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}