# GREP QUICK REFERENCE CHART ###### tags: `adobe` `print` `design` `indesign` `cheatsheet` `table` `regex` `GREP` ## Wildcards --- | WILDCARDS | | | - | :-: | | Any Digit | `\d` | | Any Letter | `[\l\u]` | | Any Character | `.` | | Any White Space | `\s` | | Any Word Character | `\w` | | Any Lowercase Letter | `\l` | | Any Uppercase Letter | `\u` | --- ### Any Digit finds each single digit: Mary had 3 little lambs. Her whole flock was made up of these three, and 15 fully-grown sheep. ### Any Letter finds each single letter (uppercase or lowercase): Mary had 3 little lambs. Her whole flock was made up of these three, and 15 fully-grown sheep. ### Any Character finds each single character (except line break): Mary had3 little lambs. Her whole flock was made up of these three, and 15 fully-grown sheep. ## Locations --- | LOCATIONS | | | - | :-: | | Beginning of Word | `\<` | | End of Word | `\>` | | Word Boundary | `\b` | | Beginning of Paragraph | `^ ` | | End of Paragraph | `$ ` | | Beginning of Story | `\ ` | | End of Story | `\Z` | --- ### Beginning of Paragraph: Mary had 3 little lambs. Her whole flock was made up of these three, and 15 fully-grown sheep. ### End of Paragraph: Mary had 3 little lambs. Her whole flock was made up of these three, and 15 fully-grown sheep. ### End of Story: Mary had 3 little lambs. Her whole flock was made up of these three, and 15 fully-grown sheep. Her sister, Shari, didn’t have any sheep at all. ## Repeat --- | REPEAT | | | - | :-: | | Zero or One Time | `? ` | | Zero or More Times | `* ` | | One or More Times | `+ ` | | Zero or One Time (Shortest Match) | `*?` | | One or More Times (Shortest Match) | `+?` | --- ### Zero or One Time: The item may appear one time in sequence, or it may not appear at all. ### Zero or More Times: The item may appear any number of times in sequence, or it may not appear at all. ### One or More Times: The item appears one time or more in sequence. ### Shortest Match: Keeps the search to the first complete sequence. Without “shortest match,” InDesign looks to the whole paragraph for the sequence. ## Match --- | MATCH | | | - | :-: | | Marking Subexpression | `()`<br>`(parentheses)` | | Non-Marking Subexpression | `(?:)` | | Character Set | `[]`<br>(square brackets) | | Or | `|`<br>(pipe character) | | Positive Lookbehind | `(?<=)` | | Negative Lookbehind | `(?<!)` | | Positive Lookahead | `(?=)` | | Negative Lookahead | `(?!)` | --- ### Offset text as expressions: Use parentheses to offset an entire expression or to group items together. For instance, in Find/Change, if you are looking for a string of 10 digits, but you want to return them in a different order, or insert additional information between the groups, use parenthesis. **Example** - format a phone number from a 10-digit string: `3035551212` In Find/Change: `(\d\d\d)(\d\d\d)(\d\d\d\d)` This will see each group separately. You could then return only the 2nd and 3rd groups, if wanted. (See “Found” expressions) ### Look for something OR something else: Use the straight slash (or pipe character, located over the backslash) to indicate either this item OR that item. You can have multiple items, each divided by the pipe character, but you need to enclose this OR search in parenthesis. **Example** - look for the word “grey” or “gray.” You could easily look for the whole word spelled both ways, but the only difference is the letter “e” or “a.” The search will always look to the entire string on either side of the pipe character. Look for: `gr(e|a)y` - Will find: grey AND gray Look for: `(Red|Green|Blue)` - Will find: Red, Green, AND Blue Look for: `(color filled|fill color|color)` - Will find each of these phrases ### Look before or after to find a string: Use Lookahead and Lookbehind to locate a string and affect just that string. **Example:** Find digits after a decimal point by using a Positive Lookbehind. Looking behind the text (what appears before), if the string exists (the decimal point in this case), then do something with the searched text (the digits). Look for: `(?<=\.)\d+` To find this: 123.45 Use Positive Lookbehind `(?<=)` and add in the decimal point. However, since the decimal means something specific in GREP, you need to “escape” the decimal to indicate you’re looking for an actual decimal. That is the backslash before the decimal. Put that inside the parentheses as well so it finds an entire string. The next part, the `\d+`, is looking for any digit, one or more times. You can then do something to the found portion, which is the `45` in the example above. ## Symbols --- | SYMBOLS | | | - | :-: | | Bullet Character | `~8` | | Backslash Character | `\\` | | Caret Character | `\^` | | Copyright Symbol | `~2` | | Ellipsis | `~e` | | Paragraph Symbol | `~7` | | Reg. Trademark Symbol | `~r` | | Section Symbol | `~6` | | Trademark Symbol | `~d` | | Open Parenthesis | `\(` | | Close Parenthesis | `\)` | | Open Brace | `\{` | | Close Brace | `\}` | | Open Bracket | `\[` | | Close Bracket | `\]` | ## Hypens and Dashes --- | HYPHENS AND DASHES | | | - | :-: | | Em Dash | `~_` | | En Dash | `~=` | | Discretionary Hyphen | `~-` | | Nonbreaking Hyphen | `~~` | ## Break character --- | BREAK CHARACTER | | | - | :-: | | Standard Carriage Return | `~b` | | Column Break | `~M` | | Frame Break | `~R` | | Page Break | `~P` | | Odd Page Break | `~L` | | Even Page Break | `~E` | | Discretionary Line Break | `~k` | ## Variable --- | VARIABLE | | | - | :-: | | Any Variable | `~v` | | Running Header (Paragraph Style) | `~Y` | | Running Header (Character Style) | `~Z` | | Custom Text | `~u` | | Last Page Number | `~T` | | Chapter Number | `~H` | | Creation Date | `~O` | | Modification Date | `~o` | | Output Date | `~D` | | File Name | `~I` | | Metadata Caption | `~J` | ## Other --- | OTHER | | | - | :-: | | Right Indent Tab | `~y` | | Indent to Here | `~i` | | End Nested Style Here | `~h` | | Non-joiner | `~j` | ## Markers --- | MARKERS | | | - | :-: | | Any Page Number | `~#` | | Current Page Number | `~N` | | Next Page Number | `~X` | | Previous Page Number | `~V` | | Section Marker | `~x` | | Anchored Object Marker | `~a` | | Footnote Reference Marker | `~F` | | Index Marker | `~I` | ## White space --- | WHITE SPACE | | | - | :-: | | Em Space | `~m` | | En Space | `~>` | | Flush Space | `~f` | | Hair Space | `~ ` | | Nonbreaking Space | `~S` | | Nonbreaking Space (Fixed Width) | `~s` | | Thin Space | `~<` | | Figure Space | `~/` | | Punctuation Space | `~.` | | Third Space | `~3` | | Quarter Space | `~4` | | Sixth Space | `~%` | ## Quotation marks --- | QUOTATION MARKS | | | - | :-: | | Any Double Quotation Marks | `“ ` | | Any Single Quotation Mark | `‘ ` | | Straight Dbl Quotation Marks | `~”` | | Double Left Quotation Mark | `~{` | | Double Right Quotation Mark | `~}` | | Straight Single Quotation Mark | `~’` | | Single Left Quotation Mark | `~[` | | Single Right Quotation Mark | `~]` |