Help with query and {{escapeRegexp (@page.name)}}

I have the following silverbullet structure:

I am trying to build a query where inside john.md I can show the documents linked to his performance.

So, inside john.md I have something like:

```include
page: "[[Library/Personal/Query/1-1-section-report]]"
```

And Library/Personal/Query/1-1-section-report.md is looking like this:

---
tags: template
---

## Incoming tasks
```query
task where name =~ /{{escapeRegexp (@page.name)}}/ where done = false render [[Library/Personal/Query/Task]] 
```

---
## Performance reviews
```query
page where name =~ /Performance/{{escapeRegexp (@page.name)}}\/ select name order by name desc render [[Library/Core/Query/Page]]
```

My problem is in the ## Perfomance reviews query, as the escapeRegexp is not working in this case because it translates it to:

 name =~ /Performance/person/john/ 

notice the person/ part within the result.

Does anyone know how to modify the query and escapeRegexp to exclude person/ from it?

Thanks

It seems that replace() could be a good way to go but i am not yet there.

Missing something:

```query
page where name =~ /Perfomance\/{{replace((@page.name), /(^[\/]person\/)(.*)/, "$2")}}/ select name order by name desc render [[Library/Core/Query/Page]]
```
Parse error in: page where name =~ /Perfomance/person/john/ select name order by name desc render Page

Ok,
I think i found a solution

```query
page where name =~ /Performance\/{{replace((@page.name), /person\/(.+)/, "$1")}}\/ select name order by name desc render [[Library/Core/Query/Page]]
```

Note that as of 0.8.1 operands of =~ and !=~ can also be strings and expressions that result in strings (which will then be converted into a regex), so you should now also be able do things like where name =~ "Performance/" + replace(@page.name, /person\/(.+)/, "$1") (not tested, but should work)

1 Like

Oh,
I love this option much more, very elegant.

I confirm it works :slight_smile:

Bonus: this works in template fenced code blocks, which your other approach does not (because you cannot use this syntax in templates)

1 Like