# Test if string.find outputs nil not working as expected

**URL:** <https://community.silverbullet.md/t/test-if-string-find-outputs-nil-not-working-as-expected/2342>\
**Category:** Lua\
**Created:** [May 9, 2025, 7:00am UTC](https://community.silverbullet.md/t/test-if-string-find-outputs-nil-not-working-as-expected/2342 "2025-05-09T07:00:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![moogoat](https://community.silverbullet.md/user_avatar/community.silverbullet.md/moogoat/32/1332_2.png) [@moogoat](https://community.silverbullet.md/u/moogoat)\
**Post date:** [May 9, 2025, 7:00am UTC](https://community.silverbullet.md/t/test-if-string-find-outputs-nil-not-working-as-expected/2342/1 "2025-05-09T07:00:44Z")

</div>

I am using the `string.find` function but finding an unexpected output when checking if it returns `nil`. However, it seems to work if I use `string.match`. I am new to Lua so just wondering if this is expected behaviour, and if so, why?

- `${nil == nil}` returns `true`
- `${string.find("a", "b")}` returns `nil`
- `${string.match("a", "b")}` returns `nil
- `${string.match("a", "b") == nil}` returns `true`  
but…
- `${string.find("a", "b") == nil}` returns `false`!

Am I doing something wrong?

For context, I am trying to write a query that finds all tasks containing a certain string but it just outputs all tasks instead:

```auto
${query[[
      from index.tag "task"
      where string.find(name, "instalment") ~= nil
  ]]}

```

However, the same query with `string.match` works fine:

```auto
${query[[
      from index.tag "task"
      where string.match(name, "instalment") ~= nil
  ]]}

```

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Maarrk](https://community.silverbullet.md/user_avatar/community.silverbullet.md/maarrk/32/56_2.png) [@Maarrk](https://community.silverbullet.md/u/Maarrk)\
**Post date:** [May 9, 2025, 7:53am UTC](https://community.silverbullet.md/t/test-if-string-find-outputs-nil-not-working-as-expected/2342/2 "2025-05-09T07:53:09Z")

</div>

I just ran your examples in regular Lua and they should work as you expected. I think you found a bug in SilverBullet, can you open an issue on GitHub? Just copying your post would work, maybe you can include the link to this thread.

---

<div class="post-metadata">

**Author:** ![lochel](https://community.silverbullet.md/user_avatar/community.silverbullet.md/lochel/32/912_2.png) [@lochel](https://community.silverbullet.md/u/lochel)\
**Post date:** [May 9, 2025, 9:37am UTC](https://community.silverbullet.md/t/test-if-string-find-outputs-nil-not-working-as-expected/2342/3 "2025-05-09T09:37:56Z")

</div>

This might fix it: [Fix string.find by lochel · Pull Request #1390 · silverbulletmd/silverbullet · GitHub](https://github.com/silverbulletmd/silverbullet/pull/1390)
