How to find Blocks with Tag A excluding Tags Starting with "B."

I need to find blocks with t.rejected while excluding blocks which refs starting with “r.”.

Example
B1 #t.rejected should match
B2 #t.rejected #r.xyz should not Match

#+BEGIN_QUERY
{:title "All blocks with Rejected Tag excluding r.* "
:query [:find (pull ?b [*])
     :where
     [?b :block/refs ?p]
     [?p :block/name "t.rejected"] 
    (not 
       [?b :block/refs [:block/name "r.zn.b"]]
    )
]}
#+END_QUERY

Above query is able to exclude blocks with exact match “r.zn.b” but not sure how to change it to startswith using [(clojure.string/starts-with? ?name "r.")]

You just need a few extra variables in there.

#+BEGIN_QUERY
{:title "All blocks with Rejected Tag excluding r.* "
:query [:find (pull ?b [*])
     :where
     [?b :block/refs ?p]
     [?p :block/name "t.rejected"] 
    (not 
       [?b :block/refs ?r]
       [?r :block/name ?name]
       [(clojure.string/starts-with? ?name "r.")]
    )
]}
#+END_QUERY
1 Like