Regex: how to remove any given string of words

In my documents, I frequently insert notes and other small items that are meant only for my own eyes, and that I don’t want to appear in the compiled text. I could of course use Annotations for this, but these are already in use for something else; moreover, in the inspector there are no Annotations. Perhaps Regex is here the way to go.

So what I need (I think) is the Regex syntax for: “Replace with nothing (= remove) any given string of signs between certain boundaries”. But I can’t find it. Online there a quite a few Regex tutorials, but those that I found are all far too bulky and complex, and don’t give clear-cut answers to very simple questions like this one.

Any help appreciated!

Have a look at Styles! One of the lesser known capabilities of styles is that the marked text can be removed from the output if you set up your compile Format to do so. The “Highlight” colour feature that can be applied to styles is useful here, as it stands out as well as annotations do, but of course since they are styles they can have other visual attributes as well.

To set them up in the compiler:

  1. Open File ▸ Compile..., and double-click on the compile Format you use in the left sidebar.
  2. In the Styles pane, select the “annotation” style you created, and click the Delete text of this style, and save settings.

The neat thing about this approach is that since the decision to delete the text is in the Format itself, different formats can delete different kinds of comments. You may not need it in this case, since these are all for yourself, but it can come in handy for proofing notes and such.

I use the following regex for similar purpose:
\[\[@:([^}]*)\/\]\]
This regex sits in the ‘Replace’ field of the Replacements pane of the main Compile window of the project I want it for; the ‘With’ field is left blank. What this does is catch instances of text spans that begin with [[@: and end with /]]. Of course, since the ‘With’ field is left empty, the effect is to remove these bracketed comments.

This solution may be useful if you need removal of text spans in areas where styles cannot be applied.

I think you could do that without regex with less trouble, replacing

[[@:$1]] with a blank field.

(I think you meant the ending string to be ]], not /]].)

Either way, the style solution seems niftier to me.

Thanks all for your kind answers!

I have been working with Scrivener since the times of Scrivener Gold, yet there are always new things to discover! This feature of Styles is another stroke of Keith’s genius; simple, efficient and very convenient. But I can get it working only in the main editor, not in the (inspector) footnotes. Is it correct that this feature doesn’t work in the (inspector) footnotes? If this should be so, then for the footnotes I would have to find some other solution.

I didn’t manage to get working the second and third solution, doubtless because of my lack of experience in this field. Is it correct that in [ [ @ : $1 ] ] all signs must be separated by a white space, except “$1”? And is it correct that the text to be omitted must be between double square brackets, and that between the two brackets, and between brackets and text there must be a white space too? For example: [–[–text to be omitted–]–], where “–” is the white space?

No, you do not need intervening spaces and probably do not want them as that would make the text you want to suppress harder to type. Just invent a beginning sequence and an ending sequence to use (that will never otherwise occur!). May it is just [[ and ]]. Those would be what you type around a span of text to be suppressed.

Now, I don’t see how to make drmajorbob’s suggestion work. I tried it and could not get it to work. For what it is worth, I tested the technique with text spans to be suppressed in the Document Notes area, but I could not get it to work.

However, my own regex-based trick works as advertised. Adapted for the simpler bracketting suggested above, the regex for that is just \[\[([^}]*)\]\]

That would catch and suppress both
[[This is a note to be suppressed.]]
and
[[ This is a note to be suppressed. ]]