[Skip to content]

2.8.18. Search & Replace

Lets you perform string Search & Replace operations during formatting.

Figure 2.94. Search & Replace settings page

Search & Replace settings page

2.8.18.1. Scope

Lets you configure the elements for which Search & Replace should be performed.

String Literals

Enables Search & Replace for string literals. Please note that you first need to define at least one pattern in order to be able to enable Search & Replace! See Section 2.8.18.2, “Patterns” for information on adding patterns.

Since 1.7

Example 2.890. String literal

String literal = "String literals are enclosed in double quotes";

Single-line comments

Enables Search & Replace for single-line comments. Please note that you first need to define at least one pattern in order to be able to enable Search & Replace! See Section 2.8.18.2, “Patterns” for information on adding patterns.

Since 1.7

Example 2.891. Single-line comment

// Single-line comments are similar like in C++

Multi-line comments

Enables Search & Replace for multi-line comments. Please note that you first need to define at least one pattern in order to be able to enable Search & Replace! See Section 2.8.18.2, “Patterns” for information on adding patterns.

Since 1.7

Example 2.892. Multi-line comment

/* Multi-line comments are similar like in C/C++ */

Javadoc comments

Enables Search & Replace for Javadoc comments. Please note that you first need to define at least one pattern in order to be able to enable Search & Replace! See Section 2.8.18.2, “Patterns” for information on adding patterns.

Since 1.7

Example 2.893. Javadoc comment

/**
 * Javadoc comments are basically multi-line comments using
 * a special notation
 */

2.8.18.2. Patterns

Lets you define regular expression patterns to use for Search & Replace. You can define an arbitrary amount of Search & Replace patterns that are executed in the order defined when formatting a file. The list component displays all patterns currently defined. Use the button bar on the right to add, remove or change patterns and define the order in which the patterns should be applied.

Jalopy uses Java’s build-in regular expression engine which is roughly equivalent with Perl 5 regular expressions. The syntax is explained here: http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html. For a more precise description of the behavior of regular expression constructs consult Mastering Regular Expressions [Friedl97].

Add...

Lets you add new Search & Replace patterns. Pressing the button will invoke a new dialog where you can enter the Search & Replace patterns.

Figure 2.95. Add Search & Replace pattern

Add Search & Replace pattern

Enter the search pattern in the Search for text field and the replace pattern in the Replace with text field. The replace pattern may contain variable interpolations referring to the saved parenthesized groups of the search pattern. A variable interpolation is denoted by $1, $2, or $3, etc.

Suppose you have the search pattern b\d+: and you want to substitute the b's for a's and the colon for a dash in parts of your input matching the pattern. You can do this by changing the search pattern to b(\d+): and using the replace pattern a$1-. When a substitution is made, the $1 means "Substitute whatever was matched by the first saved group of the matching pattern." An input of b123: after substitution would yield a result of a123-. For the given patterns

Tank b123: 85  Tank b256: 32  Tank b78: 22

would become

Tank a123- 85  Tank a256- 32  Tank a78- 22
Edit...

Lets you alter an already defined Search & Replace pattern. This button is only available if an item is currently selected in the pattern list. Pressing the button will invoke a new dialog where you can change the Search & Replace patterns for the currently selected item in the pattern list.

Figure 2.96. Change Search & Replace pattern

Change Search & Replace pattern

Please refer to Section 2.8.18.2, “Add...” for an explanation of the available regular expression capabilities.

Remove

Lets you remove an already defined Search & Replace pattern. This button is only available if an item is currently selected in the pattern list.

Up

Lets you change the position of an already defined Search & Replace pattern in the pattern list. This button is only available if an item is currently selected in the pattern list and this is not the topmost item.

Down

Lets you change the position of an already defined Search & Replace pattern in the pattern list. This button is only available if an item is currently selected in the pattern list and this is not the last item.