Bug in Find form when using regular expressions

I have many instances of text similar to this across my work:

(0953 UTC-4 (EST))

I want to change it to be like this:

(0953 EST (UTC-4))

So, I came up with a regular expression for the Find dialog’s Find field:

UTC([±]\d{1,2}) ((\w{3})))

and a Replace expression:

$2 (UTC $1))

The Find regex works exactly as expected.

However, after clicking Next, if I click Replace, or Replace & Find, I get:

(0953 $2 (UTC UTC-4 (EST))))

Obviously, in the code behind these buttons, Scrivener is treating $1 as the entire match, and is not using the capturing group for $2 at all.

When I click Replace All, I get: (0953 EST (UTC -4)) as expected.

Can Scrivener be updated so that when using regular expressions, the replacement behavior of Replace and Replace & Find is similar to that of Replace All? I don’t always want to replace every instance I find, and having to replace every instance found by a regex just to get the replacement syntax to work is annoying… especially if its across a large amount of text.

I am using Scrivener for Windows Version: (1463331) 64-bit - 03 Nov 2021

UPDATE: the forum changed +- into ± in my post, maybe in yours as well.

I think you need [-+] or [±], not [±], but otherwise I don’t have a clue. On my Mac, project replace finds documents with a match, but Find doesn’t find those matches.

I am not sure how you got that pattern to work at all, in fact, as it has mismatched parentheses, some of which are meant to be literal characters. This is what works for me:


(UTC[-+]\d{1,2}) \((\w{3})\)


$2 ($1)

However that aside, once I fix the pattern and test the bug, I can reproduce it, so I’ll get that written up. Meanwhile you can make use of the Selected Text mode for “Replace All” to limit its scope to areas you’ve determined are safe to bulk change.

It appears that the forum software has significantly altered my regex pattern…

However, the point is that some of the buttons on the Find form are buggy. Any functioning regex pattern will do to demonstrate that.

How did you enter the code in that post?

Yes, indeed, I built the reproduction case for the developers using a much simpler test with three captures instead of two, to better show how it all gets attached to $1.

5 posts were split to a new topic: Project Search hangs with regular expressions