# Is there a way to RegEx Search for Keywords (or exclude results that contain specific keyword)?

**URL:** <https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338>\
**Category:** Scrivener for Windows\
**Tags:** support\
**Created:** [June 9, 2020, 9:00pm UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338 "2020-06-09T21:00:26Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattgor123](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/m/51bf81/32.png) [@mattgor123](https://forum.literatureandlatte.com/u/mattgor123)\
**Post date:** [June 9, 2020, 9:00pm UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/1 "2020-06-09T21:00:26Z")

</div>

Hi guys, I’m currently using Scrivener : 1.9.8.0 and absolutely loving it for keeping notes and working on a little non-Fiction manuscript. Perhaps I’m using the functionality completely wrong, but all of my Notes are organized with Keywords, so for example I have keywords for things like “Table Needed” and “Organized” and “Free” and “Subscription”.

Is there a way I can search through all of my notes for items that have the below keyword combinations::

[_] “Table Needed” and “Free”? (meaning: all items that have BOTH the Table Needed and the Free Keyword)  
[_] “Table Needed” and NOT “Subscription”? (meaning: all items that have the keyword Table Needed that DO NOT also have the Subscription keyword)?  
[_] “Free” AND “Subscription”? (ideally, this would be an empty set, but I’d like to double-check)  
[_] “Free” OR “Subscription”? (ideally, this would be all of my notes, but I’d like to double-check)

Basically I’m hoping to use Scrivener as a combination of a note-taking device and a personal database and I’m struggling to figure out how to search more effectively. I’ve seen RegEx references on the forums, but struggling my way through it.

I’d really, really appreciate any advice! Thanks!

---

<div class="post-metadata">

**Author:** ![legacy\_rdale](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/l/85f322/32.png) [@legacy\_rdale](https://forum.literatureandlatte.com/u/legacy_rdale)\
**Post date:** [June 10, 2020, 1:27pm UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/2 "2020-06-10T13:27:12Z")

</div>

One thing that will simplify searching is to make sure your keywords are all one string of (visible) characters. This is because the search fields in Scrivener are typically space-delimited, so if you search for “Table Needed”, and don’t specify “all words” (when using non-regex searches), you end up matching to any key word that contains “table” or “needed”. And if you do specify “all words”, that makes it impossible for you to search for anything with an “OR” relationship. So either use TableNeeded or Table\_Needed, or some other variation that keeps the words connected by non-space characters.

Now, on to your problem.

One thing you can do for OR relationships in regex, is to use the pipe | symbol. That counts as an or.

You can also try parentheses:  
(This|That) It  
… to get This OR That AND It.I’m not sure if a space is the best delimiter after the parenthesis, however. Not sure how the keywords are presented to the RegEx engine. You’ll have to fiddle with it a bit, see if you can discover a workable solution.

If you want a NOT operator, I think this would work for excluding a document that is tagged with either or both of the keywords This and That.  
^(This|That)

If you’re trying to find keywords with an “AND” relationship… I’m not sure how to accomplish that. “This That”, would match a line that had both words, in that order, with a space between them. But if the keywords are presented to the RegEx engine as “That This”, for instance, that wouldn’t match. Better to turn off the regex option, and just choose “all words”.

I hope some of this turns out to be helpful. Sorry that I didn’t have a chance to check out if those solutions actually work, but I don’t currently have access to the Windows computer where I had the beta installed. Good luck!

---

<div class="post-metadata">

**Author:** ![krastev](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/krastev/32/12843_2.png) [@krastev](https://forum.literatureandlatte.com/u/krastev)\
**Post date:** [June 10, 2020, 2:17pm UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/3 "2020-06-10T14:17:19Z")

</div>

> [@rdale](#):
>

I don’t think the RegEx is working in 1.9, but I may be wrong.

---

<div class="post-metadata">

**Author:** ![mattgor123](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/m/51bf81/32.png) [@mattgor123](https://forum.literatureandlatte.com/u/mattgor123)\
**Post date:** [June 10, 2020, 4:13pm UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/4 "2020-06-10T16:13:57Z")

</div>

Oh gosh, I feel like such a dummy! I didn’t realize there was a Beta version out with full RegEx support. I will try installing that and working forward (worst case, I’ll just revert to my existing build).

Thanks a lot for the really helpful tip to make all Keywords “single strings” without spaces. I’ll start using CamelCase for them.

I’m still struggling to get the NOT operator to work with RegEx. I can’t seem to find all documents without a certain keyword.

I noticed when I installed the Release Candidate it expires at the end of June – do we typically get new releases in time? Or am I gonna be stuck?

EDIT: Now it seems all my Keyword searches are broken. I’m a bit confused 😕

---

<div class="post-metadata">

**Author:** ![krastev](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/krastev/32/12843_2.png) [@krastev](https://forum.literatureandlatte.com/u/krastev)\
**Post date:** [June 10, 2020, 4:33pm UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/5 "2020-06-10T16:33:21Z")

</div>

> [@mattgor123](#):
>
> I’m still struggling to get the NOT operator to work with RegEx.

There is no NOT operator in RegEx.  
Yes, there will be a new version

---

<div class="post-metadata">

**Author:** ![mattgor123](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/m/51bf81/32.png) [@mattgor123](https://forum.literatureandlatte.com/u/mattgor123)\
**Post date:** [June 10, 2020, 5:46pm UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/6 "2020-06-10T17:46:45Z")

</div>

> [@krastev](#):
>
> > [@mattgor123](#):
> >
> > I’m still struggling to get the NOT operator to work with RegEx.
> 
> There is no NOT operator in RegEx.  
> Yes, there will be a new version

Is there a possible workaround you can think of to get a search to give me all notes I have with “Table\_Needed” Keyword and NOT the “Free” Keyword as one search result.

---

<div class="post-metadata">

**Author:** ![krastev](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/krastev/32/12843_2.png) [@krastev](https://forum.literatureandlatte.com/u/krastev)\
**Post date:** [June 10, 2020, 8:24pm UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/7 "2020-06-10T20:24:41Z")

</div>

I don’t know how you can achieve that. And there may be a possible bug with the negative lookahead regex. Hope someone more knowledgeable will chime in.

---

<div class="post-metadata">

**Author:** ![theswede](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/theswede/32/81_2.png) [@theswede](https://forum.literatureandlatte.com/u/theswede)\
**Post date:** [June 11, 2020, 7:53am UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/8 "2020-06-11T07:53:56Z")

</div>

> [@rdale](#):
>
> If you want a NOT operator, I think this would work for excluding a document that is tagged with either or both of the keywords This and That.  
> ^(This|That)

Scrivener appears to be using PCRE for RegExp, which would make ^ match start of string. PCRE has no NOT operator, to my knowledge.

---

<div class="post-metadata">

**Author:** ![mattgor123](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/m/51bf81/32.png) [@mattgor123](https://forum.literatureandlatte.com/u/mattgor123)\
**Post date:** [June 11, 2020, 5:41pm UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/9 "2020-06-11T17:41:13Z")

</div>

Hm, it seems like Scrivener may not be the perfect tool for the job then. I was hoping it could be nice as a personal database & manuscript all-in-one but if I can’t exclude certain keywords, it won’t work for my needs.

I could try to make a feature suggestion, but it seems like people have been using this perfectly for ten years without it, so I think I should probably just find the perfect tool for the job before I go too far.

I guess one solution would be to add “negative” keywords as well, like “TableNotNeeded” … but doing that (and remembering to apply it) seems a bit farfetched for all of my keywords.

---

<div class="post-metadata">

**Author:** ![DavidR](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/davidr/32/78_2.png) [@DavidR](https://forum.literatureandlatte.com/u/DavidR)\
**Post date:** [June 11, 2020, 5:57pm UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/10 "2020-06-11T17:57:42Z")

</div>

> [@mattgor123](#):
>
> Hm, it seems like Scrivener may not be the perfect tool for the job then. I was hoping it could be nice as a personal database & manuscript all-in-one but if I can’t exclude certain keywords, it won’t work for my needs.
> 
> I could try to make a feature suggestion, but it seems like people have been using this perfectly for ten years without it, so I think I should probably just find the perfect tool for the job before I go too far.
> 
> I guess one solution would be to add “negative” keywords as well, like “TableNotNeeded” … but doing that (and remembering to apply it) seems a bit farfetched for all of my keywords.

For the personal database aspect, you might take a look at Evernote. It doesn’t use RegEx searching, but does have a [search grammar](https://help.evernote.com/hc/en-us/articles/208313828) that allows you to either include or exclude tags applied to a note.

---

<div class="post-metadata">

**Author:** ![devinganger](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/devinganger/32/18082_2.png) [@devinganger](https://forum.literatureandlatte.com/u/devinganger)\
**Post date:** [June 11, 2020, 8:58pm UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/11 "2020-06-11T20:58:55Z")

</div>

> [@theswede](#):
>
> > [@rdale](#):
> >
> > If you want a NOT operator, I think this would work for excluding a document that is tagged with either or both of the keywords This and That.  
> > ^(This|That)
> 
> Scrivener appears to be using PCRE for RegExp, which would make ^ match start of string. PCRE has no NOT operator, to my knowledge.

[stackoverflow.com/questions/139 … -operation](https://stackoverflow.com/questions/13908803/pcre-regular-expression-with-not-operation)

EDIT: But, this may run you into the bugs that someone (was it Lunk, I think?) mentioned with these features.

---

<div class="post-metadata">

**Author:** ![mattgor123](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/m/51bf81/32.png) [@mattgor123](https://forum.literatureandlatte.com/u/mattgor123)\
**Post date:** [June 11, 2020, 9:06pm UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/12 "2020-06-11T21:06:33Z")

</div>

> [@DavidR](#):
>
> For the personal database aspect, you might take a look at Evernote. It doesn’t use RegEx searching, but does have a [search grammar](https://help.evernote.com/hc/en-us/articles/208313828) that allows you to either include or exclude tags applied to a note.

Thanks a lot for the suggestion. I am loving Scrivener and the organizational / hierarchical structure it has. The synopsis/corkboard feature is just amazing. Plus I’ve already typed up so many notes! I’d hate to have to copy and paste them all over into another piece of software, lol.

But, I guess if there’s no simple way to do the powerful search like they have in Evernote, it may be my only choice. I hope there’s some workaround I can come up with, though I’m certainly not a Regex wizard.

---

<div class="post-metadata">

**Author:** ![legacy\_rdale](https://forum.literatureandlatte.com/letter_avatar_proxy/v4/letter/l/85f322/32.png) [@legacy\_rdale](https://forum.literatureandlatte.com/u/legacy_rdale)\
**Post date:** [June 12, 2020, 12:44pm UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/13 "2020-06-12T12:44:20Z")

</div>

You could try adding another custom metadata field that has 2 values: Free/Paid. Then a document can only have one or the other; and if you select your other search results, and view them in outline mode so that you can see which documents have which value. You can even sort such an outline view by that column to group the documents by that custom metadata field.

---

<div class="post-metadata">

**Author:** ![krastev](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/krastev/32/12843_2.png) [@krastev](https://forum.literatureandlatte.com/u/krastev)\
**Post date:** [June 12, 2020, 1:57pm UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/14 "2020-06-12T13:57:34Z")

</div>

Or the devs can look into why the negative lookahead doesn’t work. :mrgreen:

---

<div class="post-metadata">

**Author:** ![theswede](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/theswede/32/81_2.png) [@theswede](https://forum.literatureandlatte.com/u/theswede)\
**Post date:** [June 14, 2020, 1:52pm UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/15 "2020-06-14T13:52:53Z")

</div>

> [@devinganger](#):
>
> [stackoverflow.com](http://stackoverflow.com)

Good to see that was not the case, even though not all those answers are correct for most PCRE engines. And notably, the Scrivener engine seems to have some bugs.

So the [^exlude\_this] pattern works in the PCRE, at least. I just did a quick test in the Windows RC, but it didn’t do what I expected. I don’t have time to look at that right now, but I probably did something strange; PCRE is not my usual regex engine.

---

<div class="post-metadata">

**Author:** ![devinganger](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/devinganger/32/18082_2.png) [@devinganger](https://forum.literatureandlatte.com/u/devinganger)\
**Post date:** [June 15, 2020, 7:52am UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/16 "2020-06-15T07:52:29Z")

</div>

> [@theswede](#):
>
> Good to see that was not the case, even though not all those answers are correct for most PCRE engines. And notably, the Scrivener engine seems to have some bugs.

Yeah, it is definitely the case that not all PCRE implementations are created equal. But considering what the P in PCRE is, that’s pretty much par for the course. 🙂

---

<div class="post-metadata">

**Author:** ![krastev](https://forum.literatureandlatte.com/user_avatar/forum.literatureandlatte.com/krastev/32/12843_2.png) [@krastev](https://forum.literatureandlatte.com/u/krastev)\
**Post date:** [January 28, 2022, 4:21pm UTC](https://forum.literatureandlatte.com/t/is-there-a-way-to-regex-search-for-keywords-or-exclude-results-that-contain-specific-keyword/50338/17 "2022-01-28T16:21:04Z")

</div>

I know some time have passed, but would it be possible for the devs to take a look into this issue.

I mean, I could not be the only one who would like to be able to search for specific keywords while excluding others.

Tnx,  
M
