Regex for an embedded query to match all lines between 2 words

Things I have tried

file:(cdo)  (/(Status.*?$.+?endstatus.*?$)/smi)

This seems to work fine on

Please forgive my ignorance. Any help to get the right would, really, be appreciated

What I’m trying to do

I’m trying to show all lines between the word “Status” and the word “endstatus” as in the below snippet

Some text

## Status
- This is some Stuff
- Some more some more stuff


Some text

Help anyone? :blush:

I’ve got a feeling Obsidian doesn’t take options in regex - if you try the regex in the search bar, and ask it to explain the search term then you’ll see it’s using the options as extra text to match.

I’ve been away for a while. Sorry for the late reply

Any tips on how to do this then?

My regex skills are iffy

I think my answer was unclear, I don’t think you can use a regex to do this in Obsidian, though I’d love to be corrected.

The regex you would need to use would have to use the options /smi as you correctly surmised. However, Obsidian doesn’t just ignore those options, it assumes they are extra text to search for. If you copy the regex you used into the search bar and click the question mark button, Osbidian will explain what it is actually searching for:


Here, you can see that it’s trying the regex AND the smi as text to look for.

So, you can’t use the regex options, which you need for this search. Hence you can’t use a regex for this.

There may be other options but I don’t think a regex is one. I’m in the habit of writing a quick Python script for some Obsidian purposes but it might be possible to use one of the community plugins in some way, perhaps by changing the layout of what you’re searching for.

Sorry I can’t help more.

See Search

Need help from someone to show me clever way to do it without passing those options to whichever regex engine is being used

Thanks, so much. for replying to me

Does this work for you?

file:(cdo) /^## Status(.*\s)*#endstatus$/
1 Like


file:(cdo) /^## Status(.*\s)*?#endstatus$/

should work better if you have more than one

## Status

section in the same file

1 Like

I believe this will do the trick:

file:(cdo) /(?<=## Status)(.*\n)+?(?=#endstatus)/

It uses a positive lookbehind ((?<=## Status)) and a positive lookahead ((?=#endstatus)) to assert the presence of those two markers. It uses a non-greedy match ((.*\n)+?) so that it can find multiple instances in the same file.

Let me know if you need further assistance.



Thank you so much. Although your version put the helper process into a flat spin :blush: (100% CPU) - and I have an M1 mac mini with 16GB

The one offered by @macedotavares did the trick :+1:

I can’t thank you enough

This works perfectly

Thank you so much :pray:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.