Let regex work with tag: and section: search operators

To clarify, I want to note that this request has been edited as we incrementally realized that all but the tag: and section: operator already work. Originally, I was asking for something broader, as evidenced by the discussion below.

Use case or problem

It could be helpful to use regex in conjunction with the tag: search operator in order to get fast results limited to tags while also using the magic of regex.

Proposed solution

Let regex search work in conjunction with both the tag: and the section: search operator.


Thanks!

1 Like

Regex already works with those things (at least path: and tag:; I didn’t check all). Is it not working for you?

1 Like

Thanks so much! I was probably doing something careless when testing earlier, but it wasn’t working for me on Obsidian Desktop, granted I was so sure this wasn’t already implemented that I obviously didn’t test as thoroughly as I should have. Now, after just seeing your reply, I tried it on Obsidian Mobile and something like path:/.*\/media/ worked perfectly. This is so awesome!

I will mark this as a solution because I surely take your word for it. Tomorrow, I am definitely going to further investigate on Desktop, and worst case scenario could just create an isolated feature request if it turns out one or more of them don’t work. But, I am very excited to see this functionality. It is very useful.

It’s weird that I can’t get really get a tag: search to work on Obsidian Mobile at the moment. Again, I am probably doing something careless. I am sure I will figure it out later. Out of curiosity, could you add an example of a tag: search that worked for you. I am trying all sorts using syntax like tag:/.*/ and I still can’t get any results.

Thanks again for breaking this great news!

Oh, I misunderstood you! I thought you were trying to do something like /.+dog.+/ path:media. I’m glad it worked anyway, or that at least path: works. Now that I actually know what you want, I see that tag: doesn’t work for me either (on mobile or desktop, tried a few ways on desktop). I wonder if it’s related to the lack of autocomplete for tag searches.

1 Like

Thanks! I adapted the request and am going to unmark this as solved so this topic doesn’t close and since I think the discussion here is better than starting anew. Again, I really appreciate that you replied and mentioned that it already works, even if there was a miscommunication on my part. Otherwise, I would never have realized that path:regex and file:regex searches already work.

It seems that section:(regex) kind of works but not really. I definitely am going to be looking deeper into all of them later. I will add more information as I find it.

1 Like

Thanks for doing the research to find which ones work!

I’m not sure if regexes as used by Obsidian are line-based, but if so then we don’t need them to work with line:() — altho it’d be simpler and less confusing if they did.

1 Like

I think you are right. For some reason when I just retested line: and section: it didn’t occur to me to add the parentheses like the popup suggests. And, they worked perfectly. In the past, I think I must have been using the parentheses incorrectly, causing the regex searches to behave unpredictably. But, now I can get all the search operators to work with regex except tag:. And, upon rechecking the search operators section in the help…

https://help.obsidian.md/Plugins/Search#Search+operators

… I realized that the parentheses are shown for all. So, I assume they are not required but allowed. Regardless, progress has been made. Thanks for helping move this forward. I guess I can just edit the request to allow regex to work with tag: now. Life is good.

1 Like

Oh, good! I just noticed those parentheses in the help recently (I think when I was looking up file: and path?) and because I’d been successfully searching without them (I used quotes when needed) I guessed they’d just needlessly carried over a programming language convention into the documentation or something (what a charitable outlook! :roll_eyes:). I should start using them.

I’m hoping that the regex problem with tag: has the same root as the autocomplete problem so we can get 2 fixes in 1. :slight_smile:

1 Like

I very much agree! Thanks again!

Upon further testing, it appears that section: actually does not work correctly with regex. It appears to behave just like line: or simply not specifying a search operator whatsoever.

I apologize to all for the confusion. From here on in, I will try to get to a more definitive conclusion before posting requests and edits.

Thanks.

Well, sometimes figuring these things out is a process. I end up editing half of my posts (including this one, to add this sentence).

1 Like