How to write the regex to filter the following item?

- [ ] eee [[900]]
- [ ] bcd [[800]]
- [ ] eee
- [ ] eeedeee
- eee
- bcd
- eee
- eeedeee

The above is a list. I want to filter the 3rd item out, i.e. - [ ] eee, only.
How can I write the regex expression?

I’m having trouble understanding what you need.

  1. Do you mean the exact content of these lines, or something more general, like “the third line” or "all the - [ ] eee"s?

  2. Do you want the regex search to return the line ("- [ ] eee") or everything but that line?

1 Like

Sorry for the ambiguity.

I’d like to use this regex in the obsidian search panel.
I want to find out all the items which satisfies:

  1. it is a todo, i.e. the item start with \[ \]
  2. the item is not ended with a backlink, i.e. the end of the item is NOT \[\[.*\]\]

I tried the following:
/\[ \]/ -/\[ \].*\[\[.*\]\]/

but it does not work.

OK, thanks for making it clear.

I think this will do what you need:

/^- \[ \] .*?[^\]]$/

I assume that you’re using the more standard - [ ] (with a dash and a space at the beginning) to mark your to-dos. If indeed you omit them in your usage, the expression would be /^\[ \] .*?[^\]]$/.

You can see it in action and have it explained bit-by-bit it by opening this link. Note that you don’t need to put the expression inside forward slashes in this case.

Hope this helps. If you need further assistance, just let me know.

Thank you for the reply!
It solves the problem I posted.

However, unexpectedly, another issue is raised. :rofl:(now it is solved)

https://regex101.com/r/XeRB3Q/2

There are other 2 lines are matched. I guess it may relate to the newline below the item.

Any clue to cure this?

-------Updated---------
It is solved! I added a word boundary condition based on your regex.

It now looks like the following:

^- \[ \] .*?[^\]]\b$

Thank you again for the regex and the wonderful tool!

1 Like

@macedotavares, I played around with that regex site and got some weird results. As schrodinger observed (pun intended), the act of observing something disturbs it. In this case, I’m thinking there might be some oddities in how the site implements regexes such that it’s adding another layer of necessary interpretation, further clouding the issue. To wit, using the same input with Linux egrep gives different results.

@GLight, it might be easier (and run faster) to break this up:

/^- [ ] / -/\]\]$/

Translation: Begins with a check box but doesn’t end with ]]
It’s not explicitly spelled out in the help, but you CAN use more than one regex with booleans on the same search, as above.
I haven’t tested this but “it should work.” :slight_smile:

1 Like

It was the OP that ultimately fixed my regex expression. I’d probably keep hitting the wall. Anyway, as I understand it, there are several regex engines, each with their own quirks and I’m guessing something like that may be at work. (This explanation fits better within my non-Copenhagen quantum beliefs :laughing:)

I didn’t know we could combine multiple regexes with search operators in Obsidian! Thanks for the tip.

@macedotavares, my pleasure sir. Once I read up on the boolean search operators, I realized it would probably work, tested it and it did. That opens up a lot more complex searches. In this particular case, the regex phrase “.*” can be expensive. By using two separate regexes, it reduces the problem to two plain string searches by separately defining the beginning and end, and not caring what’s in between.

1 Like