Want to find all consecutively repeated words in your manuscript? Here's the search string to do it...

Came across this gem online when semi-automating the editing of my MS:

Run a RegEx search in Scrivener using this string and it will find all the consecutively repeated words you’ve accidentally created during your writing and editing process (e.g. “the the”):

\b([A-Z]+)\s+\1\b
1 Like

Ho ho! Very nice.

Here’s a couple of regex snippets I regularly use – inputting them via text replacements (Prefs/Keyboard/Text)

[a-z]+ (replacement string: !word)
(?-i) (replacement string: !cs)

(?-i) makes the query case-sensitive and saves clicking into the dropdown and toggling. (There’s also a bug with toggling case-sensitivity when you have multiple projects open. This sidestep the bug entirely.)

[a-z]+ is useful for more complex searches where you don’t care what word is in that place. It’s not really a word, but a string, so can be used to compose words (e.g. [a-z]+ly).

1 Like

Very very useful useful, thanks thanks.

Merx Merx

1 Like

Hi johnnyalpha and auxbuss,

Very nice indeed!

Not only did I learn about using the RegEx search in Scrivener (which as a RegEx neophyte I’d never done) but I found more than a dozen instances of repeated words :blush: … I can see a whole new world of possibilities here …

I need to look into auxbuss’s suggestions as well! Thank you for your suggestions!

Are there resources for neophytes either of you would recommend to get started with RegEx?

Thank you both,
scrive
:smiley:

1 Like

Hi auxbuss,

Thank you for the RegEx references …

Given the flexibility and power of johnnyalpha’s RegEx snippet as an example, is there perhaps a book or listing of RegEx ‘recipe’ snippets promulgated anywhere … I can imagine such a listing could be very helpful for writers, et al.

Like Matryoshka dolls, Scrivener has so many layers … the more one learns, the more there is to learn … I am in awe at the depth the application continues to show …

Thanks again,
scrive
:smiley:

Update: A simple search for “RegEx ‘recipe’ snippets” yielded an entire listing of ‘Regular Expression Recipes’ at GitHub, a book titled “Regular Expression Recipes for Windows Developers …”, and a site for “Free Online Regular Expression Tester” among others … Enjoy!!
scrive
:smiley:

After searching for additional useful RegExrecipes’ (following johnnyalpha’s original RegEx post) for those of us familiar with the old-style ‘LexisNexis’ style search, I’ve located the following RegEx search* that will locate two words in your Scrivener document(s) that are within X words of each other.

\b(?:word1\W+(?:\w+\W+){0,X}?word2|word2\W+(?:\w+\W+){0,X}?word1)\b

For example, if you want to locate (and highlight) all the occurrences of the two words ‘placeholders’ and ‘manuscript’ in Scrivener document(s) that occur within 5 words of each other, the RegEx code to use in a RegEx search that is available via the Scrivener Binder would be:

\b(?:placeholders\W+(?:\w+\W+){0,5}?manuscript|manuscript\W+(?:\w+\W+){0,5}?placeholders)\b

This can be a powerful tool for writers looking for words that may not appear immediately before or after each other in their documents, but together have some significance.

HTH,
scrive
:smiley:

1 Like

Here’s a nifty article describing the steps to use RegEx codes for those unfamiliar with them. It also gives a few example codes and other resources on using them.

https://www.lancymccall.com/blog/using-regular-expressions-in-your-scrivener-editing-process

1 Like

Hi KruizerChick,

Lancy McCall’s website lists a number of excellent RegEx expressions (as well as several excellent writing suggestions). In her section entitled ‘How Does It Work?’ Lancy presents an effective, step-by-step explanation (including screenshots) on how to implement RegEx expressions as a tool with Scrivener. She follows that up with her discussion on ‘Using RegEx While Editing’ that demonstrates how writers can use RegEx expressions to streamline their writing .

Lancy’s list made me wonder if L&L might consider creating a list of useful RegEx expressions, much like the ‘List of All Placeholders’, and make the list available as a distinct item on the Scrivener Help menu, possibly as a ‘List of Useful RegEx expressions’ ?

Thanks for the link,
scrive
:smiley:

2 Likes

I just used \b([A-Z]+)\s+\1\b to find double words in a 100k print adaptation I’m working on in Scrivener. Worked like a charm! Not only that, but RegEx also works in Affinity Publisher to find any number of carry-overs from Word docs.

Lancy’s article (linked above in KruiserChicks’s post) has a nice list of more searches.

2 Likes

I will be presenting Regular Expressions for Writers in the Editing chapter of my upcoming book about Scrivener :stuck_out_tongue_winking_eye:

Lancy has updated her site and the new link to this article is: https://lancymccall.com/using-regular-expressions-in-your-scrivener-editing-process/

2 Likes