Regex working for macOS, but not Windows if referral back is at very start of replace

Hi guys and gals, first and foremost thank you for making such great software to write!
Scrivener has been part of my workflow (or rather everything except final layout) since December 2016 & it’s honestly been great, which is why I don’t have to bother you a whole lot :smiley:

I’ve found a bug, though. I’ve got a project where I’m replacing in export the type of quotes. The regex is the following:
([\s])„ should be changed to $1»
([^\s])“ should be changed to $1«

The $1 is the matching pattern from inside the brackets, not literal. This pattern is correct, as I’ve tested the export many times under macOS. Now I’ve recently opened the very same project under Windows and here the regex has problems if the $ sign is at the very beginning of the replacement field.

This can be replicated in the Find & Replace too. If there’s a leading blank or whatever, it works just fine. However, I don’t want any extra characters before the match, it doesn’t make any sense.

System and Versions:
OS is windows 10, Professional 64bit
Version of Scrivener: Version: (2025341) 64-Bit - 19 Mai 2023 (according to update check it’s the newest available version)

I can’t remember the macOS versions it worked under, but it was the one that came before Ventura (Monterey?), and it worked fine, never had any problems.

To take away the expected questions:
“Have you thought of justreplacing the quote character?”
yeah, but that’s not really the point here. Regex not properly working if beginning with a $ under Windows if it works under macOS seems like a bug or at least an inconsistency in the documentation.

“Are you using regex correctly?”
I think so? But if I’ve overlooked some special remarks in the documentation or forums on referencing submatch-sets when at the beginning of the replace-line, I’d greatly appreciate a hint in the right direction!

Cheers in advance!

p.s.: this was originally sent via the contact-us-site, but issued a “Undelivered Mail Returned to Sender” receipt. Re-Sending it via e-mail produced no error, but this was mid-April and there was no answer, so here we go via forum.

Mac and Windows use different flavours of RegEx. I can’t advise on the Windows end, but for that is your friend. It covers most of the flavours of RegEx (apart from the one provided by Apple), lists all the tokens and what they mean and lets you construct and test your strings.



1 Like

Thank you for the resource!
Maybe it’ll be worth to add that to the Placeholder Help File?

Personally, I wouldn’t put it there as it’s not a Scrivener placeholder. But even though I’m a Mac user, I have it bookmarked in my browser.




Well, unfortunately the resource didn’t really help – the example works over there, but I’ve found this old case that describes this bug: Problems with RegEx search and replace - #3 by GreyWolf

so it is indeed a bug, not just different flavours of regex. The capture group is referred to as $1, no change there, and works if it’s not the very start of the string.

Sorry for the late reply.

Yep, you’re right, it is a bug. As I said, I’m on a Mac, so can’t help with Windows.

And by the way, there is a bug or lacuna in the Mac implementation, as it doesn’t recognise the code for upper/lower case conversion. It is possible on the Mac, as Nisus Writer Pro (built on the same text engine and also using RTF as its native format) can do it. That said it’s possible that the good folks at Nisus have done something behind the scenes to make it work.