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.

    {Regular expression in Search Results view}

  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.

    {Search results for the regular expression}

  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.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.