Regex doesn’t match

What I’m trying to do

I want to find tags within tasks with the help of a regular expression:

description regex matches /#tasks/ZKSV\d[4]/

Things I have tried

The tasks:

- [ ] Test ZKSV 2025/2026 #tasks/ZKSV2526  
- [ ] Test ZKSV 2024/2025 #tasks/ZKSV2425 

The tasks query:

not done
description regex matches /#tasks/ZKSV\d[4]/

This code finds the task with the tag #tasks/ZKSV2425, but not the task with the tag #tasks/ZKSV2526. I don’t get why. If I change #tasks/ZKSV2526 to #tasks/ZKSV2425 in the same task, the task is found. I also escaped the forward slash, just to be sure. It didn’t make a difference.

I use Obsidian v1.8.7

The slash must be escaped in regex but as I tried with your tasks just now, I had even zero results.
I tried adding $ at the end and ^ in front, even .*? to match anything in front, and [0-9]{4} for the digits, nothing.
I didn’t restart Obsidian as I don’t want to lose my work now.
Could be some bug.

No, the slash does not need to be escaped with the Tasks plugin: Regular Expressions - Tasks User Guide - Obsidian Publish

Thanks for testing my code!

1 Like

The nicer version of that regex do include escaping the forward slashes, so I’d use this regex all day:

description regex matches /\#tasks\/ZKSV\d{4}/

When you do \d[4} you’re matching against a number, followed by a character class, [...], consisting of the single character 4. What you really want is to limit the count of the digits, through the use of {...}.

1 Like

Thanks for pointing me to this stupid typo!

Now I am all the more surprised why #tasks/ZKSV2425 was found …

Why surprised? It’s pure (bad?) luck. You got a digit, and then the digit 4 just as you asked for… :stuck_out_tongue:

As I said, zero results for me for any kind of regex I tried, with the correct syntax…?
So is it working for OP or not.