Standard Simple RegEx Expressions not working in Scrivner

For instance, the expression…

\b[A-Z][a-zA-Z]*\b

or

[A-Z][a-z]*

… should find all words begining in a capital letter. But it instead seems to be finding all sorts of word strings, some of which do and most of which don’t match the indicated pattern. I’ve tested this expression in other environments that support RegEx. Works everywhere else. What am I doing wrong? Is RegEx broken in Scrivener on Mac?

Make sure to uncheck “Ingnore Case”.

ignore

Where is this “Find Options” panel? I don’t see it in Settings or Project Settings. I don’t see it in any menu.

In the search dialog:

1 Like

If you’re using project search, be sure that “Case Sensitive” is selected in the bottom “Options” section of the search magnifying glass menu.

1 Like

The RegEx: \b[A-Z][a-z]+(?:\s[A-Z].)?(?:\s[A-Z][a-z]+)+\b yields…

… in RegEx.com’s test, but yeields…

… in Scrivener. Anyone know why? This isn’t fixed, as some have suggested, by setting scrivener’s search preferences to “Ignore Case” (or not). If anyone can tell me how to make RegEx work in Scrivener I would vary much appreaciate it. If indeed as it seems (I have tried a great many RegEx expressions in Scrivener and very few have worked as expected), is wonky and doesn’t really work, it would be nice to know that as well.

Thanks, Randall

1 Like

Not working here, are you one a Mac or PC?

Scrivener 3.3.6 (16305) on macOS 15.0.1 (24A348)

Question: Why would one have to tell Scrivener to (or not to) pay attention to case, if case is being overtly specified in a Regular Expression?

That’s for the devs to answer, I don’t know.

What I know is: If my pattern says “find every dog” and there’s an option “Ignore Dogs”, I would turn that option off. (Or “Include All Animals” on, if it otherwise excludes dogs for some reason.)

How could you run a case insensitive search if you don’t have a switch? This is how regex fundamentally works across all engines: What are regex modifiers, and how to turn them on? and Regular Expressions | ICU Documentation

Note: there are many subtle differences between flavours of regex, just because an online regex engine says A it does not mean that is how regex works or that another engine is wrong. The Scrivener manual specifies the regex engine macOS Scrivener uses is ICU:

Scrivener uses the stock RegEx engine supplied by the Mac, which uses the UTF-8 compatible ICU guidelines. ICU is mostly compatible with PCRE, which is considered to be the standard for extended regular expression syntax. — §11.7 page 285

I prefer to use https://regex101.com in PCRE mode as it should match similarly for testing and learning, but that doesn’t guarantee identical matching so you may need to get into the weeds:

Remember: with great power comes great responsibility… :nerd_face:

3 Likes

Maybe I got out of bed on the wrong side this morning, but your assumption here irks me. Regex is a complex tool, and you obviously are fairly naive as you don’t even know about case insensitivity flags, yet you feel (“as it seems”) you know more than the ICU engine, Apple or the Scrivener developer. Humility in face of limited knowledge is always to right path to take… <rant-mode off>

3 Likes

fwiw, I use regex exclusively. I have Case Sensitive unchecked and add (?-i) to my query when I require it to be case sensitive. Works 100% of the time. I do hundreds of queries a day.

(I have a keyboard replacement set for (?-i) to make things easier.)

2 Likes

@Randall_Lee_Reetz So, to expand on the replies of @nontroppo and @auxbuss, we started here with your original pattern:

\b[A-Z][a-z]+(?:\s[A-Z].)?(?:\s[A-Z][a-z]+)+\b

Doesn’t work, unless you enable the “Case Sensitive” option:

But you’re not limited to this approach. You can also just use the pattern:

(?-i)\b[A-Z][a-z]+(?:\s[A-Z].)?(?:\s[A-Z][a-z]+)+\b

(notice the (?-i) at the beginning) and then the menu option makes no difference at all:

2 Likes