Search and replace using a regular expression | Qt Creator Manual

- Qt Creator Manual
- Search and replace using a regular expression
- Qt Creator Manual 13.0.1

How To

# Search and replace using a regular expression

Search and replace across files using regular expressions in the Search Results view.

Regular expressions used in Qt Creator are modeled on Perl regular expressions. For more information about using regular expressions, see QRegularExpression.

For example, to replace equality checks (`foo == bar`) with a function (`foo.equals(bar)`):

1. Commit your changes to version control, as you cannot undo the replace action.
2. Press Ctrl+Shift+F or go to Edit > Find/Replace > Advanced Find > Open Advanced Find to open Search Results.

3. In Scope, select whatever is appropriate for your search.
4. Select Use regular expressions.
5. Enter the following text in Search for:

        if \((.*) == (.*)\)

6. Select Search & Replace to see a list of search results.

7. In Replace with, enter the following text:

        if (\1.strictlyEquals(\2))

8. Select Replace to replace all instances of the text.

See also How To: Edit Code, How To: Search, and Edit Mode.

How To