admin管理员组

文章数量:1124530

In a JetBrains IDE (such as IntelliJ or RubyMine), how can I do a "Find in Files" that matches a string that spans two consecutive lines?

For example, I want to search for files in my project that have a line ending with the string "You can" immediately followed by a line beginning with the string "begin paying". As in the middle two lines of this sample:

<p>
  We are pleased to inform you that registration has been completed! You can
  begin paying your ...
</p>

In a JetBrains IDE (such as IntelliJ or RubyMine), how can I do a "Find in Files" that matches a string that spans two consecutive lines?

For example, I want to search for files in my project that have a line ending with the string "You can" immediately followed by a line beginning with the string "begin paying". As in the middle two lines of this sample:

<p>
  We are pleased to inform you that registration has been completed! You can
  begin paying your ...
</p>
Share Improve this question asked 2 days ago Jon SchneiderJon Schneider 27k24 gold badges151 silver badges180 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

In the Find in Files window, ensure that regex search (the .* button) is enabled, and then add the string \s*\n\s* between your two search terms, e.g.:

You can\s*\n\s*begin paying

The two \s* match whitespace at the end of the first line and the beginning of the second line, respectively, so that matches will be found even if the second line of code is indented (and/or if there is whitespace at the end of the first line).

本文标签: How to search for a string spanning lines (across consecutive lines) in JetBrains IDEsStack Overflow