Using Google docs, regular expressions can be used to conduct search and replace operations. I had a list of email addresses that were preceded by the address in quotes. I wanted to remove the quotes and everything between them: “Name5@something.com”
This expression found everything up to the @ sign: [“][a-zA-z0-9.]+ (I assume A-z should be A-Z)
This expression found everything: [“][a-zA-z0-9.]+[@][a-zA-z0-9.]+[“]
The replacement was null. Regex cannot be used for replacement expressions in google docs. However, BBedit does allow regex for replacement.
In this example I wanted to capitalize the first letter of each sentence in a text file. I use \n to find the new line before the next sentence. I use and then used parens to save what was found, and [a-z] to find all lower case letters that come after a new line:
\n([a-z])
The lower case letter after the new line found with the above expression was saved in the expression \1. To make that lower case letter upper case I used \U before \1
\n\U\1
(this info was found in a BBEdit tutorial)
From the Google help file for regular expressions:
Expression | Description | Example | Matches | Does not match |
. | A period represents any character in the given position. | d. | do, dog, dg, ads | fog, jog |
* | An asterisk after a character represents a search for that preceding character repeated 0 or more times. | do*g | dog, dg, dooog | dOg, doug |
+ | A plus after a character represents a search for that character displayed 1 or more times. | do+g | dog, dooog | dg, dOg, doug |
? | The previous expression is optional. | do?g | dg, dog | dOg, doug |
^ | A caret must be placed at the beginning of a regular expression. It signifies the string starts with the character(s) or sequence placed after the caret. Note: This regular expression only works with Google Sheets. | ^[dh]og | dog, hog | A dog, his hog |
$ | A dollar sign must be placed at the end of a regular expression and signifies that the string ends with the character(s) or sequence placed before the dollar sign.Note: This regular expression only works with Google Sheets. | [dh]og$ | dog, hog, hot dog | dogs, hogs, doggy |
{A, B} | The previous expression is repeated between A and B times, where A and B are numbers. | d(o{1,2})g | dog, doog | dg, dooog, dOg |
[x], [xa], [xa5] | A character set indicates that just one of the given character(s) should occur in the current position. Usually, any characters are valid within brackets, including characters mentioned previously in expressions: [xa,$5Gg.] | d[ou]g | dog, dug | dg, dOg, dooog |
[a-z] | A character set range signifies a search for a character within the given range of characters. Common ranges include a-z, A-Z, and 0-9. Ranges can be combined into a single range: [a-zA-Z0-9]. Ranges can also be combined with character sets (mentioned previously): [a-zA-Z,&*]. | d[o-u]g | dog, dug, dpg, drg | dg, dOg, dag |
[^a-fDEF] | A character set beginning with a ^ signifies a search for a character that is not within the given set. | d[^aeu]g | dog, dOg, dig, d$g | dg, dag, deg, dug |
\s | Any white-space character. | d\sg | d g, d[TAB]g | dg, dog, |