Regex Capture Groups for Query

Use case or problem

As a writer I would like to be able to specify capture groups for queries with RegEx within them.

path:(Operations/Calendar/Daily/2022/03/2022-03-07) /Summary of topics discussed/

Example:

Ideally, “Summary of topics discussed” could be removed from the query results. and only the remaining text would be returned by the query

Proposed solution

Regex Capture groups.

Example Query

path:(Operations/Calendar/Daily/2022/03/2022-03-07) /Summary of topics discussed((.|\n)*)-/

This slight modification would match only the text in the capture group. Alternatively a named, capture group could be returned somehow.

Current workaround (optional)

Just living with the annoyance.

Edit:
Issue is crossposted to [Feature Request] Regex Capture groups · Issue #8 · nothingislost/obsidian-query-control · GitHub

1 Like

If I understand you right, I think you want lookbehind assertions, not capture groups.

Lookbehind assertion: Matches “x” only if “x” is preceded by “y”. For example, /(?<=Jack)Sprat/ matches “Sprat” only if it is preceded by “Jack”. /(?<=Jack|Tom)Sprat/ matches “Sprat” only if it is preceded by “Jack” or “Tom”. However, neither “Jack” nor “Tom” is part of the match results.

Regular expression syntax cheatsheet - JavaScript | MDN

Try (?<=Summary of topics discussed)(.|\n)*.

You may still get more text than you want because Obsidian shows the context around search results and only offers limited control of it. In that case you might want to file a request for something like “Option to display only matching parts of regex searches” — something like the -o / --only-matching option for the unix shell utility grep.

1 Like