# Structural search and replace

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/help/go/2026.3/llms.txt).

> **Note:**
> Structural search supports Go, SQL, JavaScript, XML, and HTML.
>
>
>
> Go search patterns do not support every code construct. Unsupported constructs include imports, variable and constant declarations, assignments, increment and decrement statements, `break`, `continue`, `fallthrough`, and `goto` statements, empty statements, and struct field tags.

A conventional search process does not take into account the syntax and semantics of the source code. Even if you use regular expressions, GoLand still treats your code as a regular text. The structural search and replace (SSR) actions let you search for a particular code pattern or grammatical construct in your code considering your code structure.

GoLand finds and replaces fragments of source code, based on the [search templates](search-templates.html) that you create and [conditions](search-templates.html#ssr_filters) you apply.

Procedure: Search for a target structurally

1. In the main menu, go to `Edit | Find | Search Structurally` to open the Structural Search dialog.

To quickly switch to the Structural Replace dialog, click ![the Switch to Replace icon](https://resources.jetbrains.com/help/img/idea/2026.3/app-client.expui.general.refresh.svg).

2. In the Structural Search dialog, do one of the following:

* Create a template from scratch: select Draft Template from the list of templates and enter the code template (for example, `$variable$` to represent your code) in the editor area. To save your custom template for future use, click the Save Template icon (![the Save Template button](https://resources.jetbrains.com/help/img/idea/2026.3/app-client.expui.general.save.svg)) on the dialog toolbar. You can also choose to save the template as an inspection. ![Structural Search dialog](https://resources.jetbrains.com/help/img/idea/2026.3/go_structural_search_dialog.png) GoLand adds the created template to the Recent node in the template list.

* Use one of the existing templates to act as a prototype: select the necessary template from the list of available existing templates. For example, consider the following code snippet: ```GO package company import ( "fmt" "regexp" ) type Employee struct { NAME string Age int Salary float64 Email string } type Manager struct { Employee Department string } type Documents struct { Passport int SocSecurity string IDCard string BirthCert string } type Department struct { Name string Manager *Manager Employees []Employee } func (e *Employee) Work() { fmt.Printf("%s is working.\n", e.NAME) } func (e *Employee) GetDetails() string { return fmt.Sprintf("Employee: %s, Age: %d, Salary: %.2f, Email: %s", e.NAME, e.Age, e.Salary, e.Email) } func (e *Employee) IsValidEmail() bool { var emailRegex = regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`) return emailRegex.MatchString(e.Email) } ``` First, find struct declarations. Then narrow the search to a struct with four fields whose first field name contains at least two consecutive uppercase letters. From the list of existing templates, navigate to `Go | Structs` and select Struct Declaration. GoLand highlights matching structs in the open file. Click Find to search for these constructions in the entire project. ![the Existing Templates dialog](https://resources.jetbrains.com/help/img/idea/2026.3/go_existing_templates.png)

3. The Structural Search dialog shows the selected template and the values of its filters. You can edit existing filters or add new [conditions](search-templates.html#ssr_filters) , such as regular expressions or [script constraints](search-templates.html#script_constraints) . Place the caret on a code variable and use the filter area to manage its filters.

To try the Count modifier, select the `$field$` variable and set its Max value to `3`. The highlighted results are now limited by this setting and should include no more than three fields.

![the Edit filters popup](https://resources.jetbrains.com/help/img/idea/2026.3/go_Edit_filters_popup.png)

Next, replace the template with the following pattern to match exactly four fields. Set the Count modifier's Min and Max values to `1` for each variable.

```GO
type $name$ struct {
	$field$ $fieldType$
	$field1$ $field1Type$
	$field2$ $field2Type$
    $field3$ $field3Type$
}
```

4. In this example, add a Text modifier for the `$field$` variable.

5. For the Text modifier, enter the following regular expression:

```REGEX
\b[A-Za-z]*[A-Z]{2,}[A-Za-z]*\b
```

Select Match case. This expression matches field names made of letters that contain at least two consecutive uppercase letters. In the sample code, the pattern matches `Employee`, whose first field is `NAME`.

![Add a regular expression in the filter dialog](https://resources.jetbrains.com/help/img/idea/2026.3/go_add_filter_text_regex_ssr.png)

There are also additional options available depending on the selected language.

For example, review the following options:

* Language: use the list to select which file types to include in the search. In this case, it is Go.

* Target: use the list to select what item to search for.

* Injected code: if selected, injected code such as JavaScript in HTML or SQL in Java is included in the search.

* Match case: if selected, the search results match the case of the search target.

6. Specify the search scope: a project, module, directory, or a custom scope.

7. Click Find.

GoLand shows the results in the Find tool window.

![Find tool window results](https://resources.jetbrains.com/help/img/idea/2026.3/go_ssr_find_tool_window_results.png)

You can add the new search template to [structural search inspections](creating-custom-inspections.html) as a custom template. To do this, click Create Inspection from Template in the Find tool window. You can then reuse it to inspect your code.

Procedure: Share search templates

You can share a search template with your peers by exporting or importing it.

1. In the Structural Search dialog (`Edit | Find | Search Structurally`), [create a new search template or use the existing one](#to_search_structurally).

2. To export a template, click ![the Export Template to Clipboard icon](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.general.export.svg). GoLand adds the XML representation of the template to a clipboard (press `Ctrl+Shift+V` (Windows), `⌘ ⇧ V` (macOS), `⌘ ⇧ V` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ V` (macOS System Shortcuts), `Ctrl+Shift+V` (XWin), `Ctrl+Shift+V` (GNOME), `Ctrl+Shift+V` (KDE), `Alt+Y` (Emacs), `Ctrl+K, Ctrl+V` (Sublime Text), `⌘ K, ⌘ V` (Sublime Text (macOS)), `Ctrl+Shift+Insert` (VSCode), `Ctrl+Shift+V` (VSCode (macOS)) to see the clipboard's content). You can share this representation with other developers in chat, email, or a forum.

To import a template, copy (`Ctrl+C` (Windows), `⌘ C` (macOS), `⌘ C` (IntelliJ IDEA Classic (macOS)), `⌘ C` (macOS System Shortcuts), `Ctrl+C` (XWin), `Ctrl+C` (GNOME), `Ctrl+C` (KDE), `Ctrl+Insert` (Emacs), `Ctrl+C` (Sublime Text), `⌘ C` (Sublime Text (macOS)), `Ctrl+C` (VSCode), `⌘ C` (VSCode (macOS))) the shared XML code from anywhere (email, chat, or a forum) and in the Structural Search dialog, click ![the Import Template from Clipboard icon](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.general.import.svg). GoLand takes the XML code representation and converts it into a template including variables and a scope if it is present.

