Capture Group Search - dnGrep/dnGrep GitHub Wiki

The Capture Group Search allows using part of the file name in the search pattern within that file.

A simple example would be to search for the file extension in the contents of the file - such as "xml" in xml files and "html" in html files. But the main purpose would be to capture some part of the file name from a set of files with similar names.

To enable this feature: Set the file search pattern to "Regex", and check the new "Capture group search" checkbox.
The file filter pattern regular expression must have one or more capture groups in it.
The "Search for" field must contain numbered or named reference to capture groups. The "Search for" may be just a capture group reference or any combination of text and references to one or more capture groups. The "Search for" pattern may be of any type: Regex, Text, XPath or Phonetic. If "Search for" pattern is a regular expression and the result of the capture group substitution is not a valid regular expression, that file will be silently skipped.

Some simple examples:

  1. Search for the file extension in the file contents: Paths to match: .*\.(\w+) Search for: $1

  2. Search for the last word in the file name in the file contents (and also match the previous word in the file): Paths to match: .*[\s_](\w+)\.txt Search for: \w+\s$1

  3. Using a named capture group, search for the first word in the file name in the file contents: Paths to match: (?<first>\w+)\s.* Search for: ${first}

⚠️ **GitHub.com Fallback** ⚠️