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/


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.

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

It kinda worked but caused other problems with nesting.

The latest dataview plugin now parses lists so I just use that to pull out the results.

let folder = '\"'+String(dv.current().file.folder)+'\"'
let pages = dv.pages(folder)
    .where(b => String(b.tags).includes('Meeting'))

function myFunction(sectionLink) {  
    sectionLink.type = null
    sectionLink.subPath = null 
    return sectionLink


let summaryList = pages.file.lists
    .where(z=> z.text.includes('Summary'))> (['Summary',myFunction(, z.text]))

let importantNoteList  = pages.file.lists
    .where(z=> z.text.includes('Important notes'))> (["Important", myFunction(, z.text]))

let actionsList = pages.file.lists
    .where(z=> z.text.includes('Actions'))> (['Actions', myFunction(, z.text]))

dv.header(5, 'Overview')
dv.table( ['Note', 'Meeting', 'Text'] ,