Simple Regular Expressions for ACIM CE App Users

July 15, 2023

ACIM App Users' Introduction to Regular Expressions

The Regular Expression option in Advanced Search is unfamiliar to most people with the exception of some computer programmers, like me. It can be extremely useful in searching ACIM, and often can find things you cannot find with simpler searches.

What is a Regular Expression

A regular expression is a string of characters (letters, numbers, and often including special characters such as ", \, [, and ]) that define a search pattern that is used to find matches in text, such as ACIM. A regular expression (abbreviated as "regex") can be used to find strings of text that cannot be specified in simple searches. Such searches can often locate a passage you remember in general, but you don't recall the exact wording.

For example, you might want to find where it says that the Holy Spirit resides in our minds, but don't you recall the wording. A regex could be created to match any occurrence of two words or phrases within the same sentence. For example, it could find every sentence that contains "Holy Spirit" and "mind," regardless of which phrase comes first in the sentence. Or searching for "mind" and "home" in the same sentence might do the trick. Often you can discover variations of the idea in this way.

Another example might be finding all occurrences of any one of a set of words, like "psychotherapy," "psychology," or "psychologist." without including any other words starting with "psycho." (A Stem Search that would find all words starting with "psycho" and is part of the standard search options.)

You should be aware that, besides the ACIM CE app, many text editors or word processing programs support regex searches. Beside doing searches, a regex can be incredibly useful in finding and replacing (or extracting) things like email addresses or telephone numbers, or places where you've repeatedly misspelled something and want to find and replace all of them at once. Microsoft Word has a set of search functions very similar to regex, but using different syntax. Examples of other programs that support regex include: On a Mac, BBEdit (free version available) and Nisus Writer Pro; on iOS a text editor called Textastic that supports regex; there are others as well. I don't know Windows but I know regex is supported by many apps, some free.

A few basic concepts

Special Characters

Most characters such as letters and numbers have no special meaning; they match themselves in the text being searched. But some characters have been given special meanings. The basic ones are as follows. I'll explain some of the terms later. This is just a handy reference list you can refer to after learning how to use them.

^ Matches the beginning of a line
$ Matches the end of the line
. Matches any character
\s Matches whitespace
\S Matches any non-whitespace character
\w Matches any word character (letters, numbers, etc)
\W. Matches any non-word character
\b Matches a word boundary - tion\b matches the letters "tion" at the end of a word.

  • * Repeats a character zero or more times, e.g. "e*" will match any number of consecutive e's, even no e at all
    *? Repeats a character zero or more times (non-greedy; the shortest possible match)
  • + Repeats a character one or more times
    +? Repeats a character one or more times (non-greedy)
    {count} Matches preceding character or group "count" times - e{2} matches exactly 2 e's
    {min-max} Matches preceding character or group that occurs a min number of times to a max number - e{1,3} matches 1 to 3 e's
    [aeiou] Matches any single character in the listed set
    [^XYZ] Matches a single character not in the listed set
    [a-z0-9] The set of characters can include a range
    ( ) Encloses a group of characters; (it)*xx matches either itxx or xx

You don't need to memorize these (yet). Just be aware that you cannot include any of these characters in a search without unexpected consequences (finding or not finding lots of stuff). If you need to search for one of these special characters you must "escape" them. For instance, the period character is a wildcard that matches one occurrence of any character. If you actually intended to search for a period you would need to "escape" it, which means to precede it with a back-slash, like this ".". The same is true for all the individual characters in the list including the back-slash itself.

Suppose you wanted to search a document you are writing to find anyplace where you accidentally used two spaces, " ". You could do that by typing two blanks as your regex, but what if you had accidentally typed a space and then a tab, or three spaces? You could find any kind of spaces by typing "\s\s". That finds two of any character that shows up as an invisible space: the space, linefeed, return, and tab characters all match "\s". To find two or more consecutive spaces, you could use "\s{2,}". To find "ab\" you would have to use "ab\".

A Few Examples

abc* matches a string that has ab followed by zero or more c
abc+ matches a string that has ab followed by one or more c
abc? matches a string that has ab followed by zero or one c
abc{2} matches a string that has ab followed by 2 c
abc{2,} matches a string that has ab followed by 2 or more c
abc{2,5} matches a string that has ab followed by 2 up to 5 c
a(bc)* matches a string that has a followed by zero or more copies of the sequence bc

Of course, in searching ACIM CE, you would never search for something like 2 to 5 letter c's in a row. The examples are meant to illustrate, in a simple way, the meaning of the symbols and sequences.

An ACIM Example

Here's a practical example of how you might use this regex pattern:
[^XYZ] Matches a single character not in the listed set

Suppose you want to find every occurrence of the words "Holy Spirit" in the course. If you simply search for those words, you will get a list of paragraphs with those two words in it. But they won't necessarily be together! The paragraph may have "spirit" in one place and "Holy Trinity" in another sentence. You could put quotes around it and match only the literal phrase, Holy Spirit. I find it helpful to make the app highlight not only those two words but the rest of the sentence, which makes it easier to spot. Sentences end with a period, question mark, or exclamation mark, which can be expressed in a regex like this: [.\?!]
The period and question mark are "escaped" with back-slashes. Here's how a search could look: Holy Spirit[^.\?!]*

Looks crazy, right? The set in square brackets matches anything NOT a character that ends a sentence; the asterisk says it will match zero or more such characters.

If we add the word "mind" at the end of the regex, it will match any phrase that begins with "Holy Spirit" followed by "mind" later in the sentence.

Leave a Reply

Your email address will not be published. Required fields are marked *

Register for updates

Copyright 2024 Circle of Atonement
cloud-syncearthbullhorn linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram