Learning GREP with InDesign

Learning GREP with InDesign

with Michael Murphy

 


Learning GREP with InDesign decodes the language of GREP for InDesign users. It shows how this versatile tool can be used for describing text, which can speed up or automate everyday formatting tasks. InDesign expert and graphic designer Michael Murphy introduces the basic concepts of GREP, and shows how to build powerful expressions using metacharacters. Michael also explores many of the little-known features of GREP, explaining how GREP styles and Find/Change can be used to rearrange data and dynamically format text. Exercise files accompany this course.
Topics include:
  • Using metacharacters, the building blocks of GREP
  • Describing text that may not exist with zero operators
  • Applying multiple character styles to the same text with GREP styles
  • Eliminating orphaned words at the ends of paragraphs
  • Preserving and recalling subexpressions
  • Customizing a GREP-based text cleanup script for long documents

show more

author
Michael Murphy
subject
Design
software
InDesign CS4, CS5, CS5.5, CS6
level
Intermediate
duration
3h 45m
released
Nov 18, 2009

Share this course

Ready to join? subscribe


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:00(Music playing.)
00:03Hi! I am Michael Murphy and I'd like to welcome you to InDesign CS4 Learning GREP.
00:08In this course, I'll show you how to use GREP expressions in Adobe InDesign for
00:12automatic, dynamic text formatting, and powerful search and replace operations.
00:17I'll introduce you to all of the basic and advanced concepts of GREP, including
00:21metacharacters, expressions, and how to describe text as patterns.
00:25We'll explore how GREP is integrated into Adobe InDesign in both the Find/Change
00:29feature and in CS4's new GREP Styles.
00:32Using examples designed to get anyone new to GREP started out on the right foot
00:37and anyone familiar with GREP up to the next level, I'll show you how to use
00:40GREP Styles and Find/Change to eliminate repetitive tasks and potentially reduce
00:45hours of work to mere minutes.
00:48Along the way, you'll discover many undocumented features and learn how to
00:51combine GREP with other InDesign features for even greater power and efficiency.
00:56GREP may be the greatest InDesign feature you never knew you needed.
01:00Now let's get started with InDesign CS4 Learning GREP.
Collapse this transcript
Using the exercise files
00:01If you are a Premium Member of the lynda.com Online Training Library, you have
00:05access to the Exercise Files used throughout this title.
00:08In the Exercise Files folder, each chapter in the title has its own folder.
00:13Within that, there is a folder for each movie in that chapter.
00:17That folder contains all of the files you'll need to work with to follow along
00:21with the exercise files.
00:22If you don't have access to these exercise files, you can follow along from
00:26scratch or with your own assets.
Collapse this transcript
1. GREP Basics
What is GREP?
00:01Before we can start working with GREP, let's first to find exactly what GREP is.
00:06GREP started as a command line text searching utility for the Unix Operating System.
00:11Originally, it was an acronym for the task of globally searching for a
00:16regular expression and printing the results, and the command line for that
00:20was GREP, hence GREP.
00:24Over time, that acronym has also been translated as General Regular Expression
00:29Parser among other interpretations, but whatever variation of the name is used,
00:34the regular expression part never changes.
00:37So what's a regular expression and what is parsing?
00:41A regular expression is a means of describing text, text patterns, or
00:46conditions within text.
00:48Most regular expressions don't actually have to contain any literal text at all.
00:53Text in a regular expression is described by what's called metacharacters, which
00:58stand in for actual characters.
01:01You can use individual metacharacters, like any digit, to search for one specific
01:06thing or combine many different metacharacters into an expression that
01:10describes a pattern of text.
01:13Parsing is the process of sifting through text to find the patterns described by
01:18that regular expression.
01:20Although GREP's origins are in computer programming, over the years it's
01:23found its way into many text-editing applications, which exposed it to many
01:27more nonprogrammers.
01:29Now, GREP has been built directly into Adobe InDesign, which has made it a
01:33mainstream technology available to designers, production artists, and document
01:38producers, who can really benefit from its capabilities.
01:41It may look a bit intimidating at first, but GREP is not as formidable as it
01:45seems once you understand its basic concepts.
01:48And when you see how much time it can save you, you'll find its well worth
01:51the learning curve.
Collapse this transcript
Text searching vs. GREP searching
00:01One way to begin understanding what GREP is capable of is to compare it to the
00:05text-based search and replace functions most of us are used to.
00:09A standard text only Find/Change query is literal.
00:12It looks for exact text and replaces it with other exact text.
00:17For example, you might search for every instance of dog and replace it with cat.
00:22But one GREP search can look for every instance of dog, or cat, or hamster, or
00:27parakeet, and replace all of them with pet in one step.
00:31That's an example of a condition, or is a condition this or that or another
00:36thing or something else.
00:39Text searching is also limited. While you may be able to search for any digit
00:43using a wildcard in InDesign's text-based Find/Change, it only finds one digit at a time.
00:50With GREP, however, searches can be flexible, so you could describe any digit, one
00:55or more times, and find single, double, triple, quadruple numbers, and so on.
01:02A text search looks only for characters, letters, numbers, spaces, punctuation
01:07and so on, but GREP can also look for locations, allowing you to search based on
01:12where text is, not just on what it is.
01:15GREP can also remember the text that it finds and reuse it later on, no matter
01:20how unique that specific text is, allowing you to rearrange that text, eliminate
01:25parts you don't need and add parts that you do.
01:29Primarily, GREP parses text for patterns and most text can be described as a pattern.
01:35Take, for example, a U.S. phone number, which is made up of ten digits.
01:39That number is usually broken up into smaller units of a three-digit area code,
01:44a three number exchange, and the last four numbers.
01:47So while you and I may think of a phone number as something like this, GREP
01:51thinks of that number this way, any three digits, a dash, any three digits,
01:57another dash, and four digits. That's a pattern.
02:00The numbers themselves don't matter and that's the real power behind GREP
02:04because this pattern will describe and find any U.S. phone number.
02:09And if some of them use dashes, but others use periods or someone close the area
02:13code in parentheses but others don't, GREP can handle that too.
02:18After you've used GREP a few times, you'll find you start to see patterns where
02:21you never noticed them before and as you get more confident with some of GREP's
02:25more advanced expressions, you'll be able to anticipate and account for
02:29inconsistencies in those patterns and describe any kind of text accordingly.
Collapse this transcript
Working with GREP and InDesign
00:01GREP is integrated into two completely separate features in InDesign CS4.
00:05Let's take a quick look at the two places where you will work with GREP
00:09within the application.
00:10Since InDesign CS3, GREP has been part of Find/Change, which is available from
00:15the Edit menu>Find/Change or by using a keyboard shortcut, Command+F on a Mac
00:20or Ctrl+F on Windows.
00:23The Find/Change dialog has a Text tab and a GREP tab, as well as a Glyph and Object tab.
00:29And on first glance the Text tab and the GREP tab are not terribly different
00:33from one another, until you look at a few specific details.
00:37In the Text tab, there is a Case Sensitive button and a Whole Word button.
00:43In the GREP tab, those options are not available because all GREP searches
00:47are case-sensitive by nature and there are different ways, in GREP, to
00:51describe a whole word.
00:53Also, in the Text Find/Change tab, if you go to the Special Character's menu at
00:58the end of the Find what field, there are a limited number of options available to you.
01:03In the GREP tab, if you go to that same button, there are far more options
01:07available, and most of the GREP options begin down here after the other submenu
01:12and include Wildcards, Locations, Repeat and any number of others.
01:16At the end of the Change to field, there are fewer options, but the key in GREP is
01:21this Found sub-menu, which we'll discuss in a later movie.
01:25If you are still only working in CS3, this is where you will work with GREP, and
01:29I should point out that in CS3 and CS4 there is virtually no difference between
01:35the GREP Find/Change features in either version of the application.
01:39So anything we discuss in this title about GREP Find/Change is going to apply
01:44even to the older version.
01:46The other place where you'll find GREP in InDesign is only to be found in CS4,
01:52and that is GREP Styles.
01:55You can work with GREP Styles in any of the places where you typically work with
01:59text on the paragraph level.
02:01So, if you have your Text tools selected, you can access GREP Styles from the
02:05Control panel menu, at the far end of the Control panel, by choosing GREP Styles,
02:11from the Paragraph panel, going to its flyout menu and choosing GREP Styles.
02:16But the place where you really want to be working with GREP Styles is from
02:20within a Paragraph style, because it's the only place you can really preserve the
02:25work that you do and apply it to multiple paragraphs.
02:29So if I were editing a style or creating a new paragraph style, which I'll do
02:33here very quickly, and I wanted to add a GREP Style to it, I would select GREP
02:38Style from the options on the left, and in this dialog box, in a nutshell, here, is
02:43how a GREP Style works.
02:45You create a new GREP Style.
02:47You choose, from the Apply Style menu, an existing Character Style or create a new
02:52one, and then in the to text field, you specify the GREP pattern that you want
02:57that Character Style applied to.
02:59Now, this is the tricky part. That's entirely up to you.
03:03You have the Special Characters menu that we saw on the Find/Change dialog at
03:07the end of this field as well, so you can start to build your GREP expressions
03:11with what's available here.
03:13But in order to start actually working with GREP in InDesign, you need to know a
03:17little bit more about GREP in general,
03:20specifically, what all of those Special Characters are and how you put them
03:24together to make up regular expressions.
Collapse this transcript
2. Basic Metacharacters
Using metacharacters, the building blocks of GREP
00:00The building blocks of GREP are special characters or combinations of characters
00:04known as metacharacters, which stand in for and describe different types of
00:09characters, conditions and locations.
00:13InDesign has had its own metacharacters for some time, but there are key
00:16differences between those metacharacters and GREP metacharacters that you
00:20need to know about.
00:21First, let's take a look at where metacharacters exist in InDesign already.
00:26In Find/Change, which I'll access by going to the Edit menu, choosing Find/Change,
00:32or using the keyboard shortcut Command+F or Ctrl+F on Windows.
00:38In a text-based search, if you are looking for something like a tab, you can't
00:42actually type it in this Find what field.
00:44If you do, you just jump back and forth from field-to-field.
00:48So a tab needs to be represented by something else, in this case, a metacharacter.
00:53Over to the right of that field, the special characters for search menu, the
00:57first item in the list is Tab.
00:59This is how you would indicate a tab in a search operation.
01:03When you choose that it puts in ^t. This is the metacharacter
01:07that represents a tab.
01:09If you were looking for a Hard Return, or what InDesign calls the end of a
01:14paragraph, you would choose that, and get ^p. This is the InDesign
01:19convention for metacharacter syntax.
01:22They almost all start with a caret.
01:24I am going to close this window.
01:27Another place where you might have encountered these is if you were defining a
01:30Nested style]. Say, for example, you were creating a Paragraph Style. I am going
01:35to open the Paragraph Styles panel and choose New Paragraph Style from the panel menu.
01:41If I am defining a Nested Style, under Drop Caps and Nested Styles, I will click
01:45New Nested Style, and for right now it doesn't matter what I define this as, but
01:50let's say I wanted to define a style through one tab.
01:54By default, Words is chosen here but from this menu I can choose Tab Character,
02:00and it actually puts in the text 'Tab Character'.
02:03If I were to type ^t, that would do the same thing.
02:07In fact, if I click off here, it actually swaps out the Tab Character for the
02:11metacharacter I put in.
02:13But if I were defining this Nested Style through one Right Align tab, which is
02:18^y, you'd see the metacharacter still in place.
02:22I'll cancel out of this.
02:24So these metacharacters show up in a number of places.
02:26Another one, in fact, is in InDesign's Bulleted and Numbered List function.
02:31With my cursor in this text and the Control panel in Paragraph mode, over here
02:37the Numbered List icon, if I option or Alt+Click that icon, I get the Bullets
02:42and Numbering dialog box.
02:44If I am defining a Numbered list by choosing numbers from the list type you can
02:48see here in the Number field that everything to define the formatting of that
02:53number is defined by metacharacters.
02:55There is a Number placeholder beginning with a caret, and then again, ^t for a tab.
03:00So metacharacters have been around for a while and they define a lot of
03:03things in InDesign.
03:05But their syntax is somewhat different when you are working with GREP.
03:08I am going to cancel out of this and we're going to go back to the
03:11Find/Change dialog.
03:13Edit>Find/Change, and I am going to switch over to the GREP tab.
03:17The dialog boxes look very similar, but when I go to the Special Characters for
03:21Search menu and click that, I have a much longer menu here.
03:25Tab, once again, is the first choice.
03:27If I click that, I get \t, not ^t. This is the
03:32significant difference between the syntax of InDesign metacharacters
03:36and GREP metacharacters.
03:38If I choose End of Paragraph, which is a Hard Return, I get \r,
03:43not ^p as we saw in the Text field.
03:47So that's one main difference.
03:49GREP has been around much longer than InDesign and fortunately Adobe did not
03:53create their own version of GREP and change the syntax for people who are
03:56familiar with GREP walking in.
03:59But there are a handful of characters that are entirely unique to InDesign that
04:04GREP was never intended to deal with.
04:07These are things like the Current Page Number marker or Anchored Object markers
04:11or any of the dozen custom white spaces that are available to you in InDesign.
04:17In order to account for those, there is yet another change in syntax.
04:21For example, if I click here and I choose from a Markers submenu, the Current
04:27Page Number marker character, that is described as tilde uppercase N. If I go
04:33back to the menu and choose something like a Flush Space from the White Space
04:37sub-menu, that's tilde lowercase f. These InDesign specific characters all start
04:44with a tilde instead of a backslash.
04:47So there are two syntax changes that you need to be aware of between InDesign
04:51metacharacters and GREP metacharacters.
04:54Now there are a great many metacharacters in this menu.
04:57Each of these submenus can be very long or somewhat short.
05:02But it's a lot to remember, and most of it you're probably not going to commit to memory.
05:06Basics like Tab and Return you probably will over time, but if you want to have
05:11a reference for all the different metacharacters that are available to you, or at
05:16least most of them, if you go up to the Search field in the Application Bar and
05:22simply type in 'metacharacter', hit Enter.
05:25You'll either access Adobe's Online Community Help, if you are connected to the
05:29web, or if you're not you'll get the Local Help that's on your hard drive.
05:34The first match is InDesign CS4 Metacharacters for searching.
05:39Click that link and you'll get a table that shows you the character that you
05:43are looking for, a column with the Text Search metacharacter, which is
05:47InDesign's convention, and then a column with the GREP metacharacter that you would need to use.
05:53And if you look at them side-by-side, you can see, for the most part, they are quite similar.
05:57Carets versus backslashes or carets versus tildes is about the only real difference.
06:03The End of Paragraph character is the most different.
06:05It uses a P instead of an R, but by and large, they are very similar in these two columns.
06:12There are, however, a few metacharacters that are not listed here, and we'll
06:16encounter those later on in the course.
06:19So just to review, metacharacters represent other characters and, in most cases,
06:24GREP metacharacters differ only from InDesign metacharacters, in that they begin
06:28with a backslash or tilde instead of a caret.
06:31But that's not true for every metacharacter. As with all rules, there
06:35are exceptions.
Collapse this transcript
Escaping out metacharacters
00:00A small handful of metacharacters are not preceded by a backslash or a tilde.
00:05They're made up of only one character.
00:07These include the period, the question mark, plus sign, and asterisk among others.
00:12If you need to describe any of these actual characters with GREP, it requires
00:16what's known as escaping out the metacharacter.
00:19Let's take a look at what that means.
00:21I'm going to switch to the Text tool, click inside this body copy.
00:25I'm going to open up the Find/Change dialog.
00:27I'll choose Edit>Find/ Change, switch to the GREP tab.
00:34If I'm looking for a period in this document and I type a period in the Find
00:39what field in the GREP tab, choose Find, take a look at what it found.
00:44I'm going to zoom in here so we can get a closer look.
00:48It's actually highlighted a space.
00:50If I choose Find Next, it's highlighted the next letter, and then the next
00:54letter, the next letter, and now a space.
00:56So it's finding any character, which is exactly what a period means in GREP.
01:01It's the wild card for any character.
01:04In order to find an actual period, what you need to do is put your cursor before
01:09that period here and type a backslash.
01:13This is what's known as escaping it out.
01:15The backslash changes the meaning of that period from any character to a literal period.
01:22So if I click Find, I find a period, and the next period, and the next one.
01:28I don't have those extraneous matches that I did not want.
01:32This is true of all of the single- character metacharacters in GREP.
01:38You must escape them out with a backslash if you're trying to find the literal character.
01:42I'm going to clear this out here.
01:45If, for example, you were looking for an opening parenthesis, you would find an
01:50opening parenthesis under the Symbols submenu, opening parenthesis character.
01:55When that's inserted, notice it's got the backslash before it already.
01:59The same is true if you were to choose Close Parenthesis Character.
02:03But not every character that you need to escape out is in here. The Plus sign, the
02:08Question Mark, the Asterisk and some others also require escaping out.
02:13There is no area here in the Find/ Change dialog that's going to specifically
02:18tell you every metacharacter that needs to be escaped out.
02:21So you'll have to become more familiar with them as we work.
02:25Throughout this course, I'll point out any time that a special character
02:28needs to be escaped out.
02:30Any single-character metacharacter you encounter as you work with GREP, and
02:34we'll see a lot of them throughout this course, must be escaped out if you need
02:38to find it literally.
02:40Not properly escaping out these metacharacters, when necessary, will cause any
02:44GREP expression to either produce unexpected results or fail altogether.
Collapse this transcript
Building with wild cards
00:00There are many different kinds of GREP metacharacters.
00:03Some describe specific characters while others indicate how often certain
00:07characters or portions of an expression repeat.
00:10Some describe locations and others apply conditions to searches.
00:14In InDesign, these different metacharacter types are grouped together logically
00:18in the Special Characters menu.
00:20In this movie, we're going to take a look at the first group of
00:23metacharacters called Wildcards.
00:26I'm zoomed in on the second page of this layout so that we can better see the
00:30text on the screen and my cursor is inside of this body copy text.
00:36In the Paragraph Styles panel, you can see the Body Text, which is the style in
00:40use, is highlighted.
00:42I'm going to right-click on that style name or Ctrl+Click on the Mac and
00:46choose Edit "Body Text".
00:48This opens the Paragraph Style Options dialog and I'm going to go to the GREP style area.
00:54I'm using GREP styles to demonstrate these metacharacters because it's the
00:57only way in InDesign to actually preview the results of your GREP expressions as you build them.
01:02It's very helpful to do that as you're learning this.
01:05But in order to make that work, you need to make sure that the Preview checkbox
01:09at the bottom is actually checked on.
01:13Now the GREP Style work area doesn't look like a whole lot, on first glance.
01:17It's just a big area with a new GREP Style button at the bottom.
01:20I'm going to click New GREP Style and my options here are to apply a style,
01:25which right now is set at None.
01:27If I click None, you'll see that it's actually a pull-down menu of all of the
01:31available character styles in this document.
01:35If I need to create a new character style, CS4 allows me to do that with this
01:39option at the bottom.
01:40In this instance, for this example, I'm going to use just this Yellow Highlight
01:45style that's already built into the document.
01:48Below that is the To Text field.
01:51If I click on that, instantaneously, because Preview is checked, you'll see that
01:56this default expression, which is actually any digit one or more times, is
02:01automatically applied to the text on the page.
02:04You can see all of the numbers are highlighted with this Yellow Highlight
02:08character style, which basically just puts a thick underline below the text.
02:13Now, this default cannot be changed, unfortunately, so I need to clear it out
02:18each time I start a new GREP Style.
02:20As soon as I click off in this gray area, that commits the change.
02:24So I can see the results on the page.
02:26I can still cancel.
02:28I don't have to save these changes to the style.
02:30Nothing is actually saved until I click OK.
02:33But by switching back and forth between the To Text field and clicking in this
02:37area, I can see what's going on, on the page, as I build my GREP expression.
02:42We're going to take a look at each of the Wildcard metacharacters in the
02:45Special Characters menu.
02:47At the end of the field, I'll click the Special Characters menu icon, and I'm
02:50going down to Wildcards.
02:53Any digit we've already seen.
02:55It's \d, and if I click in the gray area you can see what we saw before, that
03:01those numbers are highlighted.
03:02I'll click back in the To Text field, clear that out by hitting Delete.
03:06I'm going to go back to the Special Characters menu at the end of the field, to
03:10the Wildcards submenu, and I'm going to skip Any Letter for now because it's a
03:15unique one that we're going to deal with at the end.
03:18I'm going to go to Any Character, which is the broadest of all the
03:22wildcard metacharacters.
03:23It's the most far reaching.
03:25When I select that, I get a period, meaning any character.
03:30If I click off in the gray area to preview the results, you can see it matches
03:34exactly that, any character, punctuation, uppercase and lowercase letters,
03:39digits, spaces, everything except a hard return.
03:44That's the only thing outside of the scope of the Any Character metacharacter.
03:49I'm just going to clear that metacharacter out of the To Text field, and let's
03:53take a look at the next wildcard in the list.
03:56Under the Wildcards submenu, I'm going to choose Any White Space.
04:00Fortunately, because I'm using a character style that actually highlights the
04:05space occupied by the character with a yellow underline, this will actually show up.
04:10If I choose Any White Space, I get the \s metacharacter.
04:14I'll click in the gray area and you can see it matches Any White Space.
04:19If I zoom in here, you can see that around this em dash, I'm using two InDesign
04:25custom white spaces.
04:26They're little bit thinner than the standard Spacebar white space.
04:30These are thin spaces, and they also match, because Any White Space is matched.
04:35In fact, I'm going to click OK while this is still part of the style.
04:39I'm going to go on to the page and come over to the beginning of one of these
04:44paragraphs and I'm just going to type in a Tab.
04:46A Tab also qualifies as a white space.
04:49You'll notice that as soon as I typed it, the character style was
04:52automatically applied.
04:53This is what GREP styles do.
04:55As I add more spaces, since Any White Space is what's being styled, every
05:00white space that I add is automatically and dynamically styled with that character style.
05:05I don't actually need these, undo that change altogether and go back to the Body
05:11Text style in the Paragraph Styles panel, right-click on it, choose Edit "Body
05:15Text" and let's take a look at the next wildcard.
05:19Once again, I'll create a new GREP style, since I undid the last one.
05:24I'm going to choose Yellow Highlight again.
05:27This is the default, unfortunately, that we're going to encounter every time
05:30we start one of these.
05:33I'll clear that out, and I'm going to choose the next wildcard in the list,
05:36which is Any Word Character.
05:39Any Word Character applies the style that you choose to Any Uppercase Letter,
05:44Any Lowercase Letter, Any Digit, and the underscore character.
05:49So let's see what we get when we chose that.
05:51\w is the metacharacter itself.
05:55If I click off in the gray area, let's zoom out a little bit, so you can
06:00see some more here.
06:01You can see that it matches exactly that.
06:03Any Word Character, uppercase or lowercase letter, number or underscore, but
06:08it doesn't match white spaces, or punctuation, and none of those are highlighted here.
06:13I'll clear out that Any Word Character wildcard and we'll take a look at the
06:17next wildcard in the list.
06:20That is Any Uppercase Letter, which is pretty straightforward.
06:24It's \u. When I click off the gray area, you can see that it matches every
06:29uppercase letter, all of the ones at the beginning of sentences, the
06:34complete uppercase sentence.
06:36There's one little thing that you do need to be aware of when you choose this.
06:41I'm going to zoom in down here where this ligature is and you'll notice that
06:46InDesign is considering the whole ligature, both letters, as a single uppercase
06:51character even though part of it is actually a lowercase character.
06:56InDesign has ligatures turned on, by default, and this is how GREP treats
07:01ligatures when it encounters them.
07:03Even though you can still select them as separate characters, they're considered
07:06by GREP to be one character.
07:08So this is just something that you need to be aware of.
07:10I'm going to go back here and I'm going to choose the next wildcard from the list.
07:16I'll clear that one out.
07:18From the Wildcards menu, I'll choose Any Lowercase Character.
07:22Again, fairly self-explanatory, the metacharacter is \l. If I click in the gray
07:28area, you can see that that's what it matches.
07:31Let me zoom out here and I've matched all of my lowercase characters.
07:36You'll also notice that that ligature is not selected at all, even the h portion of it.
07:42So this treatment of ligatures by Any Uppercase Letter and Any Lowercase Letter
07:46metacharacters works both ways.
07:49I'm going to clear that out and click off here so that all of that formatting is removed.
07:55We're going to go back to the one item in that wildcard list that I skipped, and
08:01that is the Any Letter metacharacter.
08:05If I select that, you'll notice that the syntax here is quite different.
08:10It's actually the Any Lowercase and Any Uppercase Letter metacharacters
08:15enclosed in square brackets.
08:17Anything enclosed in square brackets is what's called a character set.
08:21So this is technically not a wildcard by itself.
08:25It's two wildcards combined together in a character set, which we'll discuss
08:29in the later movie.
08:31That's been included here in InDesign, because it's a very convenient choice.
08:35It's useful to have, but it's actually not a true and unique wildcard.
08:40So wildcards stand in for particular types of characters from something as broad
08:45as Any Character to more specific like Any Digit or Any Lowercase Character.
08:51Except for that Any Letter option, those are all of the documented InDesign
08:55wildcards you'll see available in this list.
08:58However, there are few wildcards that are not in the Special Characters menu,
09:03nor are they listed in the Help files.
09:05We'll take a look at some of those hidden gems, in the next movie.
Collapse this transcript
Understanding undocumented wild card "opposites"
00:00The Special Characters menu and the metacharacters for searching table in the
00:04InDesign Help files don't give you a complete list of all the metacharacters you can use.
00:09Several wildcard metacharacters are left out altogether.
00:13Let's take a look at some of these undocumented wildcards and what they describe.
00:18I'm zoomed in on the second page of this layout and my text cursor is inside of
00:22this body text and I am going to right- click on the style named Body Text in the
00:27Paragraph Styles panel and choose Edit Body Text.
00:30I am going to go GREP Style and create a New GREP Style.
00:35Once again, I'll choose the Yellow Highlight style, so that we can see what's
00:40going on on the page as I work.
00:42And when I click in here and my default is activated, as usual, but I want to
00:47leave that in here for now and quickly delete the plus at the end of that any
00:52digit metacharacter.
00:53So, it's just any digit and we can see that applied on the page.
00:56It really doesn't change anything.
00:58But if I select this lowercase d in the any digit metacharacter and type an
01:04uppercase D and click-off, I would change that metacharacter's meaning.
01:09I have now described any character that is not a digit, which doesn't just mean letters.
01:15It means spaces, punctuations, literally anything that isn't a digit.
01:20This same convention of switching from lowercase to uppercase applies to several
01:24other metacharacters.
01:25I'll clear this out, click off here, go back in this field and if I wanted to
01:32describe, for example, a Wildcard that is anything that's not a white space.
01:39If I choose Any White Space, I get \s. We would change that
01:43to an uppercase S and click off.
01:47I described anything that is not a white space, which means any character
01:52except a standard Spacebar space, a Tab, any of InDesign's custom white space characters.
01:58None of those are highlighted, but anything that doesn't meet the criteria for
02:02being a white space is highlighted.
02:05The same thing goes for any upper and lower case letter. Any uppercase letter is
02:10\u, but changing it to \U highlights
02:17everything that is not an uppercase character.
02:20Any Lowercase character, same thing. \l is any lowercase
02:25character, \L is anything but a lowercase character.
02:32And the last of these is \w, which is Any Word character,
02:39meaning any upper or lowercase letter, digit or underscore would highlight all of that.
02:46But \W would change that meaning to its opposite, so all of
02:51my punctuation, spaces, anything that doesn't fall into the criteria of being a
02:56word character, is highlighted instead.
02:59When you're putting together a complex GREP expression, it's good to know these
03:02wildcard opposites exist, because sometimes it's easier to describe something
03:07based on what it's not, rather than what it is.
Collapse this transcript
Specifying locations
00:00GREP doesn't just describe text characters in the abstract.
00:04It can also describe a specific location within text, allowing you to specify in
00:09a GREP pattern where something is, not just what it is.
00:14The thing to remember about locations, however, is that they really can't be seen.
00:18If a location such as the beginning of a paragraph is being described in GREP,
00:23it's not referring to the first character at the beginning of a paragraph.
00:28It's referring to the space that your cursor occupies when it's placed at the
00:32beginning of a paragraph, as such, highlighting something like this in a GREP
00:36Style is not really going to show you anything on the screen.
00:39For example, with my cursor in the body copy text in this file, and I am
00:44zoomed in again on page 2 of this layout to better see the text, if I
00:48right-click on the Body Text style name in the Paragraph Styles panel, choose
00:53Edit Body Text, go to GREP Style.
00:56I am going to create a New GREP Style here and from the Apply Style menu, I'm
01:01going to choose the Yellow Highlight character style.
01:04I'll clear out the default of any digit one or more times and I'm just going to
01:09describe a location, the Beginning of a Paragraph from the Locations submenu.
01:15I'll click off in this gray area to see my results on the page and I see nothing
01:22because a location can't be highlighted.
01:24Locations are almost always used in combination with other metacharacters.
01:30So, where you can describe any digit, you might want to be more specific and
01:34say, any digit at the beginning of a paragraph, so that you don't get every
01:38digit anywhere in your document and you're focusing your GREP expression on a specific location.
01:44So, if I modified this expression and instead of just saying the beginning of a
01:50paragraph, I followed that metacharacter with a Wildcard such as Any Uppercase
01:56Letter, I've changed the expression to say any uppercase letter at the
02:00beginning of a paragraph.
02:03Quite literally, as you look at it, what this describes is the beginning of a
02:07paragraph followed by any uppercase letter.
02:10If I click off here, you'll see that that's what gets highlighted on the screen.
02:16The H at the beginning of this sentence and these other two, it's not
02:20highlighting everything at the beginning of every paragraph because some of them
02:23start with quotation marks or digits, and those are not uppercase characters.
02:28So, this is what you get by describing a location in combination with
02:32another metacharacter.
02:34As a variation on this, I could look for something else.
02:37I could clear out this field here.
02:40If I'm looking for any quotation mark at the end of a paragraph, I could just
02:44type a quotation mark in the To Text field, then go over to the Special
02:48Characters menu to the Locations submenu and choose End of Paragraph, which puts
02:55in a dollar sign, which is the metacharacter for the end of a paragraph.
03:00If I click off here, that's exactly what gets highlighted, every quotation mark
03:04at the end of a paragraph.
03:07So, locations are a very good way to focus and narrow down a search and take a
03:12wildcard that might have a very broad meaning and focus it on a particular area.
03:16The other location metacharacters in here, I'll quickly run through.
03:21If I delete the dollar sign at the end of that expression and go down to
03:25Locations and choose End of Word and click off, I really don't get anything
03:31because that just isn't happening on the page.
03:33The End of Word metacharacter is backslash greater than sign.
03:37If I delete that and instead describe any quotation mark that appears at the
03:42beginning of a word, which is backslash less than sign, then I do get some
03:46results on the page.
03:47I have specifically highlighted that quotation mark at the beginning of a word,
03:51so it's occurring both at the beginning of a paragraph and at the beginning of
03:56words that exist within paragraphs.
03:59Let's take a look at another example.
04:01I'll clear out the beginning of word metacharacter from there, leaving the quote
04:04mark in, and from the Special Characters menu, I will go to Locations and this
04:09time around, I'm going to choose Word Boundary, because Word Boundary is an
04:13interesting multitasking metacharacter.
04:16If I click off here, nothing really changes, because I'm describing a Word
04:21Boundary, which can be either the beginning of a word or the end of a word.
04:26The meaning of it changes based on where it occurs in the GREP expression.
04:29In this instance, I'm saying find me a quote mark followed by a word boundary
04:34and it's giving me a quote mark followed by the beginning of a word.
04:38If I move that around, I'm going to select the backslash lowercase b,
04:43Word Boundary metacharacter, cut it to the clipboard and paste it in
04:46before the quotation mark.
04:48Now I'm looking for any word boundary followed by a quotation mark.
04:54When I click off here, as you can see, repositioning that word boundary
04:58metacharacter on the other side of the quote mark has changed its meaning.
05:01It's un-highlighted everything that had been highlighted before and you don't
05:05see anything highlighted here because nothing quite matches that criteria, at
05:09least not in the text that we can see on this page, because I've changed the
05:12meaning of that metacharacter.
05:15So, the Word Boundary metacharacter is flexible.
05:17It can mean the beginning of a word and it can mean the end of a word, and it's
05:21what you place around it that changes that context.
05:25Since the Word Boundary metacharacter is flexible to exist on either side of
05:29a word, it does have a specific use when you are using GREP in the
05:34Find/Change operations.
05:35I am going to cancel out of this and I am going to go to the Find/Change dialog
05:39by choosing Edit>Find/Change.
05:43I'm in the GREP tab and if I were looking for the word is and I click Find.
05:47I am going to find is as part of the word this, as part of isn't, and also as the word itself.
05:55If I wanted to do a whole word search, which is something you can do in normal
05:59text Find/Change by turning the Whole Word option on.
06:02If I want to do that in GREP, I have to actually place the Word Boundary
06:06metacharacter at the beginning and end of is in this field in order to define
06:11it as a whole word.
06:12So I'll go to the Special Characters for Search menu and under the Locations
06:15submenu, I'll put in the Word Boundary metacharacter at the end.
06:19I will then copy it and paste it at the beginning.
06:23And now when I click Find Next, I'm only getting the word 'is'.
06:27I am not getting 'isn't', I am not getting 'this' or any other instance of 'is' as
06:32part of another word.
06:34So, even though the Whole Word button is missing from the GREP tab of the
06:37Find/Change dialog, you can actually create a whole word condition by putting
06:43Word Boundary characters at the beginning and end of something that you want
06:46found only as a word, not as part of another word.
06:50Including a specific location in a GREP expression is an excellent way to make
06:55your expression very precise about where, and under what conditions, the text you
07:01are describing needs to be found.
Collapse this transcript
Learning the undocumented location metacharacters
00:00There are a few location metacharacters that are not listed in the Help files or
00:04available from the Special Characters menu.
00:07One of them is quite obscure, but two of them are very useful and those are the
00:12Beginning of Story and End of Story metacharacters.
00:16As you know, InDesign considers any series of threaded text frames as one story.
00:22So, while text may span many frames across many pages, if it's linked up it's
00:28considered one story and you may need to find the beginning of a story or
00:32describe the end of the story for a specific purpose in Find/Change.
00:37Let's take a look at how that works.
00:39I'll hit Command+F, or Ctrl+F on Windows to open the Find/Change dialog and make
00:44sure that I am in GREP mode.
00:46In the Find what field, to describe the beginning of a story, I'll type
00:51\A. That's the metacharacter for Beginning of Story, and I'll click Find.
00:58And my cursor is moved to the position at the beginning of this story.
01:03I'll go back and click Find Next, and my cursor gets moved to the beginning of
01:07the next story, in this next chapter.
01:10Click Find Next again and my cursor is placed in the beginning of this story,
01:15which is the chapter header.
01:17If I click Find Next, I move to the next chapter, in the next chapter header,
01:21which is a separate story, unlinked to anything else.
01:24If I click Find Next, my search is completed.
01:26There are four stories in this document and I've run this search four times.
01:31If I wanted to describe the end of a story, that metacharacter would be
01:35\Z. If I click Find, my cursor is moved to the end of this story.
01:43I'll click Find Next, my cursor is at the end of this story, Find Next again and
01:50my cursor is placed, as you'll notice, at the end of a footnote.
01:54I'll zoom in here, so we can see that better. Even though footnotes are embedded
01:58into the text frame where their footnote reference occurs. They are considered a
02:02separate story by InDesign.
02:04So, when you describe the end of a story, you have to realize that footnotes may
02:08be considered part of the match.
02:11If I click Find Next, I move to the end of this story in this chapter, Find
02:16Next again brings me to the end of this story, in the heading and again my
02:21search is complete because I've found all of the instances of an End of Story
02:25location in this document.
02:28Now, the third location metacharacter is a bit more obscure.
02:31I am going to clear out the Find what field here, and I'm going to go to the
02:37Special Characters menu and choose the Wildcard>Any Character which is a period
02:44and put my cursor right before it then go back to the menu and choose the
02:49Location metacharacter, Word Boundary and click Find.
02:54And what InDesign finds for me is any character following a Word Boundary.
02:58So, it's finding the first letter in a word, a space between words, anything
03:03that fits its criteria for a character following a Word Boundary.
03:07If I change that Word Boundary metacharacter to its opposite using uppercase
03:12B, I am not describing any character, provided it is not preceded by a Word Boundary.
03:18So, I am going to click Find and notice that it's skipped the first letter in
03:23this word, but it finds the next one, and the next one and the next one.
03:27When I click Find again, it's taking me to the second letter in this word
03:33because the first letter is preceded by a Word Boundary, so that means it
03:37doesn't match our criteria.
03:39And if I click through again, notice it's skipping the beginning of every word.
03:43If I move that not a word boundary character to after any character or
03:48metacharacter, I change its meaning to find any character as long as it's not
03:53followed by a word boundary.
03:55Click Find Next and it's finding me the T in Nights, but it's going to skip
04:01over the S. It's finding me the O in Of, but it's going to skip over the F. It's
04:06going to skip over the E in The because the ends of each of those words are
04:11followed by a Word Boundary.
04:13This is a very obscure metacharacter and I'm not quite sure where it would
04:17find practical use in your work, but you never know and there's no other way
04:20to know that it exists in InDesign because it's not available in any menu or in Help files.
04:26However, finding the beginning or end of a story is very useful if you're
04:30cleaning up text and want to eliminate extra spaces or returns, or want to
04:34insert a special character or even an anchored object at either of those
04:38locations using Find/Change.
04:40Those are both exercises that we'll work through later in this course.
Collapse this transcript
Using repeat metacharacters and defining the shortest match
00:00The next class of Metacharacters are grouped together under the Repeat submenu
00:04in both GREP Styles and Find/Change.
00:07Repeat metacharacters will always be used in combination with other
00:11metacharacters because all they describe is how often something occurs.
00:17When you describe something in a GREP style, it's going to find every instance
00:21of that expression no matter how often it appears in a paragraph. That's just
00:24how GREP Styles work.
00:25So, the best way to show how Repeat metacharacters work and the scope of a Repeat
00:31metacharacter is through Find/Change.
00:33So, I'm going to hit Command+F, or Ctrl+ F on Windows, to open the Find/Change
00:38dialog and right now it is opened up in Text mode.
00:41And I just want to point out the limitations of text-based searching versus GREP
00:46based searching in this instance because text-based searching in InDesign, for a
00:50while, has included some wildcards in the Special characters for search menu.
00:54If I click that menu and go down to Wildcards, I can describe any digit, which
01:00is ^9 in a text-based search.
01:03And if I click Find, it's going to find one digit and then another single digit
01:08and another, one at a time.
01:11If I want to find two digits, I have to put in another ^9 metacharacter and
01:16if I click Find, it will find me a pair of digits, but only a pair.
01:20It will no longer find me any single digits and it won't find three digits in a row or more.
01:26GREP works differently and the flexibility of how GREP works is
01:30extremely powerful.
01:31I am going to go to the GREP tab and I am going to put my cursor back at the
01:35beginning of this text because that's where I want my next searches to begin.
01:40And I am going to click in the Find what field, go to the Special characters
01:44menu at the end, and again, I'm going to pick a Wildcard>Any Digit and I'm
01:49going to augment that by adding the Repeat metacharacter, one or more times, at the end of it.
01:57That's the plus sign, so this expression now reads as any digit one or more times.
02:02If I click Find, I'll find that single digit, 2, but I will also find 2005.
02:10The single digit, 7, 0, this 1, but I will find 499 and 00.
02:17So I am finding single digits, double, triple and so on.
02:23This GREP expression is far more flexible than what I'm able to accomplish in a
02:27Text search even though Wildcards exist in Text searches.
02:31There is one thing specific that you need to know about these Repeat
02:35metacharacters, however, and about GREP in general.
02:38GREP, by its very nature, is greedy.
02:41It's going to find everything.
02:43It is like an obedient dog that wants to satisfy you and give you everything you
02:47possibly could have asked for.
02:48But sometimes that is entirely too much.
02:51For example, if I wanted to describe any text that exists within parentheses,
02:58I might use the expression any character one or more times and put it in parentheses.
03:03That would look like this.
03:04I'll delete this, go to the Special characters menu and from the Symbols
03:09submenu, I can choose Open Parenthesis Character because I have to escape out
03:14any opening or closing parentheses.
03:16They have a special meaning in GREP and in order to look for actual parentheses
03:21characters I need to escape them out.
03:23So that puts it in as \(.
03:27Next, I'll type in a period, for any character, and a plus for one or more times,
03:33then backslash, close parentheses.
03:35I've just described any character one or more times within parentheses.
03:40And when I click Find, here is where the problem is.
03:43I'm going to move this over. Notice it's found the opening parentheses and then
03:50any character one or more times, but a closing parentheses is also included
03:55within the scope of any character, so it kept going all the way through until it
04:00found the last closing parentheses it possibly could.
04:05If I move my cursor further up in this paragraph and do that again, you can see
04:10just how greedy this is.
04:11I will click Find and now it's found everything, from the very first opening
04:16parentheses through the very last closing parentheses and this is just too much.
04:22In order to rein this in and get just what we are looking for, we need to
04:28circumvent GREP's greedy nature and limit that search to what's called
04:32the Shortest Match.
04:34So I'll move this Find/Change dialog up here so we can see a little better and
04:39in this expression I am going to delete the plus after the period, so now I'm
04:44just describing any one character within parentheses.
04:48And with my cursor still there after the period, I'll go to the Special
04:51characters menu to Repeat, but this time I'll choose One or More Times(Shortest
04:57Match) and that puts in a plus followed by a question mark.
05:01That means one or more times shortest match.
05:05Now I'll click Find and that solves the problem.
05:08It's found the shortest match in my description of any character, up until a
05:13closing parenthesis.
05:14If I click Find Next again, you can see that it's done the same thing for this
05:19one price, this one and this one.
05:22It no longer expands that search out as far as it can go when you limit it
05:26to the shortest match.
05:28So Repeat metacharacters provide a great way for you to broaden or limit the
05:32scope of another metacharacter beyond what you can accomplish in a text-based
05:35search, but because GREP is greedy by nature and always tries to match as much
05:40as possible, it's important to know how to rein in that Repeat metacharacter.
Collapse this transcript
Specifying exact matches and ranges
00:00The one or more times metacharacter matches the most text, and possibly too
00:04much, and the Shortest Match option will limit that to the least amount of matching text.
00:09But what if you need something in between those two extremes?
00:13Suppose you need to match something exactly two times, or two or more times, or
00:18at least two times, but no more than four times.
00:21You won't find an option for that in the Repeat Metacharacters menu or anywhere
00:25in InDesign's help documentation.
00:27But it's very simple to do so.
00:29I am going to open Find/Change using Command+F, switch to the GREP tab and
00:35suppose I wanted to find any two or more numbers.
00:39I will go to the Special characters menu and under Wildcards, I will choose Any
00:45Digit and from the Repeat submenu, I can do One or More Times, I can do Zero or
00:52One Time, I can do One or More Times (Shortest Match), but there's nothing here
00:57that lets me find something exactly two times.
01:00I could go in and just type another \D metacharacter, choose Find and I
01:06will find two numbers.
01:08There, there and there!
01:11But that can get kind of tedious.
01:13That can be a lot of metacharacters in a very small field.
01:17If I want to describe something an exact number of times, I just need to put
01:22that number in braces or what's called curly brackets.
01:25I will type in an opening brace, the number 2 and a closing brace and I have now
01:31described any two digits.
01:34If I click Find, that's what I get.
01:37If I wanted to find any two or more digits, I just type a comma after that
01:43number 2 and when I click Find, it's now found three digits and here it finds
01:50two and here it finds three again.
01:53So that's changing my starting point.
01:55It's not one or more. This is a way of saying two or more.
01:59If I change that to three and clicked Find, I would find three or more digits.
02:05If I wanted to get very specific and define an exact range, for instance, at
02:09least two, but no more than four digits, I could change the 3, here, to a 2.
02:18That's my first value, and then after the comma, I'll type a 4.
02:22So now I'm describing any digit at least two times but no more than four times
02:27and if I click Find I will find the 499 here, I will find two digits here, three
02:34digits here, two here, two here and so on, throughout the document.
02:41Specifying exact ranges with this method lets you build more accurate
02:45expressions than you can with the more broad options available from the Repeat
02:49Metacharacters menu.
Collapse this transcript
Finding content that doesn't exist with zero functions
00:00Two of the most potentially confusing options among the Repeat metacharacters
00:04are Zero or One Time and Zero or More Times.
00:08Why would you want to search for, or define, something zero times?
00:12How can something that's not there be found?
00:16The simplest answer is that these particular Repeat metacharacters allow you to
00:20search for something that may or may not actually be present in your text.
00:26Let's take a look at how these work, using GREP styles.
00:30In this text, I make several references to various versions of Adobe InDesign,
00:35from CS through CS3, and let's say I want to highlight all of those instances of
00:40the product name with a specific Character Style.
00:45With my cursor in this text, I will open the Paragraph Styles panel and this
00:49text is using the Body Copy style, so I will right-click on that and choose Edit
00:53"Body Copy", go to GREP style and I'm going to create a new GREP style that
01:00applies a style in this document called Red, which does only one thing.
01:05It turns the text red.
01:07And, of course, I have my default here To Text.
01:10It puts in any digit one or more times and you can see that on the page,
01:13which is not what I want.
01:14So I'll clear that out and click off here and I want to apply this to Red style
01:19to every mention of InDesign CS through CS3.
01:23So I will just start typing in 'InDesign CS' and I'm going to stop right now and
01:32click off here and we'll see what that matches.
01:35It automatically applies the Red style to the InDesign CS portion of CS, CS2,
01:40CS3 and so on, but not the version number.
01:44To do that, I will go to the Special characters menu, down to Wildcards
01:50and choose Any Digit.
01:51That puts in the Any Digit metacharacter.
01:55If I click off, you'll see that it's kept the CS2 and CS3 references highlighted
02:03but InDesign CS is not highlighted at all because it is not followed by a digit.
02:09What I want to do, in this particular example, is cover my bases for both a
02:14mention of InDesign CS without a number and one with a number.
02:18So the number may or may not be there, which means it could be there zero
02:23times or one times.
02:25Computers don't understand may or may not, but they understand zero or one.
02:29So I will put my cursor at the end of this expression, go to the Special
02:35characters menu, down to Repeat and I'll choose Zero or One Time and that puts a
02:43question mark in after the Any Digit metacharacter.
02:47That question mark means zero or one time and it refers only to what's directly
02:52before it, which is the Any Digit meta-character.
02:55If I click off here, you will see that InDesign CS is also highlighted once
03:01again along with CS2 and CS3.
03:05The Zero or One time metacharacter attached to the Any Digit metacharacter means
03:10that if there are zero digits there, it's a match and if there's one digit
03:15there, that's also a match.
03:17A variation on this is the Zero or More Times metacharacter.
03:22If, for example, we were talking about InDesign CS25 and I needed to account for
03:27the fact that there may be no numbers or there may be more than one number, I
03:32would choose from the repeat submenu Zero or More Times.
03:37In this instance, that also works.
03:40With these Repeat metacharacters, you can build very powerful expressions that
03:45account for the possibility of a matching condition that exists in some of your
03:49text, but not in all of it.
Collapse this transcript
3. Advanced Metacharacters
Creating "or" conditions
00:00The next metacharacter we're going to look at is grouped under the Match submenu.
00:04The options in this group are among the most powerful, complex, and abstract
00:08metacharacters you'll use when you work with GREP.
00:11They handle everything from imposing conditions on your expression, to
00:15isolating smaller parts of a larger expression, to defining a custom set of
00:19valid matching characters.
00:21We're going to start with the simplest of all of these, the Or metacharacter.
00:25I'm zoomed in on the top part of page 8 in this document and my cursor is
00:30within the body text.
00:32So my Body Text style is highlighted in the Paragraph Styles panel.
00:35I'll right-click on the Style Name, choose Edit Body Text, and I am going to go
00:40to the GREP Style area to create a new GREP Style.
00:43From the Apply Style menu, I'm going to choose the existing character style, Red.
00:48That just highlights text and applies a red color to it.
00:52In the To Text field, by default, any digit one or more times is selected, but
00:56there's no effect on the page, that we can see, and I am just going to clear that right out.
01:00So now, I'm starting clean and I want to use the Or metacharacter in a
01:05practical situation.
01:06What I want to actually describe is 'his', and then from the Special Character
01:12menu, go to Match>Or, which puts in the Vertical Slash character, also called the pipe.
01:19And on the other side of that, I'm going to type 'her'.
01:22So basically, I've written an expression that says his or her and applies a red
01:27color to any text that matches.
01:29Let's click off here, and you can see that's what happens on the page.
01:34I get the 'her' in the word 'there', also in the word 'there' here, but 'her' and 'his' as
01:39whole words, the 'his' in 'this', the 'his' in 'Whispered'.
01:43So I've successfully matched his or her, but I haven't matched whole words.
01:49If I want to limit my results on the page to only instances of his or her that
01:54are whole words, and not have any partial word matches, I need to surround
01:59each word with a word boundary location metacharacter, which we've seen in a previous movie.
02:05So I'm going to go back and modify this expression.
02:07I'm going to put my cursor right at the beginning of the expression before the H
02:11in his, go to the Special Characters menu, down to Locations, and I am going to
02:17choose the Word Boundary location metacharacter.
02:19That puts a \b before the h in His.
02:23I'm also going to put one at the end of the word, after the S, another one
02:28before the H in her, and after the R in Her, and I did that simply by copying
02:34the first word boundary metacharacter, and pasting it in where I needed it,
02:37throughout the expression.
02:39When I click off, you can see that I've successfully matched just a whole word
02:43His or Her in this document.
02:45I'm going to clear this out, and let's try another example, using the Or metacharacter.
02:51On this page, there are a few Knights of the Round Table mentioned and I want
02:56to call out those names, also using the Red character style that's already selected here.
03:01In the To Text field, I'm going to just type in static text, the word Sir, and
03:06I'll type space and if I click off, you can see that highlighted on the page
03:10here before Sir Galahad, Sir Launcelot, Sir Kay, and in other places.
03:17If I wanted to highlight Sir Kay, or Sir Launcelot, or Sir Galahad, you might
03:21think that I could type in Sir Kay, go to the Special Characters menu, and
03:27choose the Match Metacharacter Or, and then just type Galahad, then another Or
03:33metacharacter and Launcelot( Sir Kay|Galahad|Launcelot).
03:36So now I'm saying Sir Kay, or Galahad, or Launcelot.
03:39Let's see what happens when I click off on the page.
03:42Well, I've matched exactly what I've described, but it may not be what I intended.
03:47I wanted to highlight Sir Kay, Sir Galahad, and Sir Launcelot.
03:51But instead, I described Sir Kay, or Galahad, or Launcelot, without the Sir before them.
03:58The Or metacharacter considers everything that proceeds it to be one choice,
04:03everything that follows it to be another choice, and it goes as far as it has to go.
04:08So it looks at Sir Kay as one thing, Galahad as another, and Launcelot.
04:13The Sir doesn't get appended to the other Knight names.
04:17So, this has to be described differently.
04:19So, one way to fix this is to go in to each part of this expression and add Sir
04:24and a space before each name.
04:28Now, each choice, this, or that, or the other is entirely specific.
04:33So if click off, it matches Sir Galahad, up here, Sir Launcelot, Sir Kay, and
04:39any other instances of that throughout the text.
04:43The problem is this is not the most efficient way to do this.
04:46It's a little bit cumbersome.
04:47It takes a little bit longer, and it makes for a longer expression.
04:52One of the problems with working with GREP in InDesign is that you only have
04:56this amount of space in the field, either here in GREP Styles or in Find/Change,
05:02to type your full GREP expression.
05:04If the expression starts to get longer, it scrolls over, and it becomes a little
05:08bit more difficult to look at the whole thing at once, and work with it, towards
05:12the far end of the expression.
05:14So we want to write this a little bit more efficiently, but in order to do
05:18that, we need to use something that's called a sub-expression, and we'll cover
05:22that in another movie.
Collapse this transcript
Building subexpressions
00:00In a previous movie, we saw how the Or metacharacter considers everything
00:04before it as one choice, and everything after it as another.
00:08But if you want to limit the Or condition or a repeat metacharacter to a
00:12smaller portion of an expression, you need to break that expression up into subexpressions.
00:18In this example, an Or condition exists that looks for Sir Kay, Sir Galahad or Sir Launcelot.
00:25The problem with that is it's not the most efficient way to do this.
00:29The Sir is repetitive.
00:31Sir only occurs once and then the Or should really just apply to the names
00:35themselves, that follow it.
00:37It takes up a lot more room in this very small working space, in the To Text
00:41field, so it becomes a problem if the expression gets longer.
00:45So one way to write this more efficiently, and the only way to rein in the Or
00:49condition to a certain part of an expression, is to use a subexpression.
00:54What I am going to do is put my cursor here, after Sir and space, select
00:59everything that follows, and delete it.
01:02From the Special characters menu, I am going to go down to the Match submenu and
01:07choose Marking subexpression.
01:09That inserts an opening parenthesis and a closing parenthesis.
01:13Anything that exists within those parentheses is considered the subexpression.
01:18The parentheses isolates that as a separate unit within the overall expression.
01:24It's also the reason why you can't just define an actual opening or closing
01:29parenthesis character by typing them in a GREP expression. You have to put a
01:32backslash before them to escape them out.
01:35I'll move my cursor in between those parentheses characters and I am going to
01:39type in those knight names.
01:40Kay, then the Or metacharacter, which is the vertical slash, Galahad, or,
01:46Launcelot and let's see what happens when I click off the page.
01:51The effect is the same.
01:52Nothing has changed from the previous and longer expression.
01:56I've isolated the Or metacharacter to only what exists within the subexpression.
02:01So when it looks to its left, here, it only goes as far as that opening
02:06parenthesis and considers just Kay, not Sir Kay, one of the choices for the Or condition.
02:12Then it looks after it for just Galahad and after the next Or metacharacter
02:16for just Launcelot.
02:17So this is a much more efficient way of writing this expression and it's the
02:21only way to limit the scope of the Or metacharacter.
02:25There are many, many uses for subexpressions and we're going to encounter them
02:29throughout this course.
02:30They're very critical part of GREP and they're going to creep up over and over as we work.
02:36Another instance where subexpressions are quite useful is to allow the repeat
02:42metacharacters, like One or More Times or Zero or One Times, to apply to a range
02:47of characters or a specific sequence of characters.
02:51For instance, I am going to click off here for a moment and move myself down the page.
02:56In the lower half of this page, you can see that Sir Kay appears up here,
03:01normally, and then later down in the page, in a couple of places, it's Sir
03:05Kay apostrophe S, in the possessive form.
03:08If I want to describe either appearance of the name with or without the
03:11possessive, I can use a subexpression to do it as efficiently as possible.
03:16I am going to go back into the Body Text options by right-clicking on Body Text,
03:20choosing Edit Body Text and going into the Paragraph Style Options.
03:24I'll move this over just a little bit so we can see a little bit more on the
03:28page and I am going to go to the GREP Styles work area and I am going to clear
03:32this expression out.
03:34In fact, I am just going to clear out everything after Kay and the beginning
03:38of that subexpression.
03:40I'll click off here and you can see only Sir Kay is highlighted here, here and
03:44here, but without the apostrophe s.
03:48Now, one way to handle this is to put the apostrophe in just by typing it and
03:52then going to the Special characters menu, choosing Repeat>Zero or One Time.
03:58That puts in the question mark metacharacter for Zero or One Time, which means
04:03it may be there, it may not be there, either is a match.
04:07Then I'll type in a lowercase s and again put in another question mark, because
04:12the s may or may not be there.
04:15I'll click off here, and you can see that in this situation it highlights both
04:19Sir Kay by itself and Sir Kay apostrophe s, two variations of the name.
04:24For something this short, with only two characters, this is probably fine.
04:29It's only a handful of metacharacters,
04:31but in a more complex pattern, you can do this a little bit more efficiently.
04:35For instance, I could delete the question mark after the apostrophe and instead
04:40I'll put my cursor before the apostrophe, type an opening parenthesis, then
04:45after the s, type a closing parenthesis.
04:48I've now define a subexpression that consists of the sequence apostrophe s as one thing,
04:55which means I only need to put one Zero or One Time metacharacter at the end of
05:00it, which is what exists here.
05:02Under normal circumstances, Zero or One Time applies only to the one character
05:06that precedes it, but when you use subexpressions that Zero or One Time
05:10metacharacter applies to the entire subexpression.
05:14So I can click off here and nothing changes on the page because this
05:18accomplishes the exact same thing, but in a slightly more compact manner,
05:22especially if it was more than just an apostrophe s and there were a number of
05:26characters in there, a whole portion of a word, for example, that you wanted to make optional.
05:31So, that's yet another use for subexpressions.
05:34subexpressions are necessary whenever a pattern, even a simple one like this,
05:38reaches a point that requires you to limit a repeat character or other condition
05:42to a small part of the overall expression.
05:45In more complex expressions, breaking a pattern into subexpressions is
05:50absolutely essential.
Collapse this transcript
Using character sets to create custom wild cards
00:00The Wildcard Metacharacters we saw in a previous movie, like any digit,
00:04any character, and so on, provide a quick convenient way to describe
00:07common character types.
00:09But you may find yourself wanting to define your own custom wildcards of
00:13specific characters to be matched.
00:15That's what the next option under the Match sub-menu, Character Sets, allows you to do.
00:20I'm zoomed in on the top part of Page 3 in this document, and my cursor is
00:25inside of the body text, which is why you see it highlighted here in the
00:29Paragraph Styles panel, where I'll right-click it, choose Edit Body Text and go
00:34to the GREP Style area.
00:35I am going to create a New GREP Style to demonstrate how character sets work.
00:40From the Apply Style menu, I am going to choose the existing Red character style.
00:45That will just color the text red on the page and the default of any digit one
00:49or more times is in here.
00:51Again, if I just click in there, you'll see that it highlights any digit on the page.
00:57That's actually a useful starting off point because any digit means any digit, 0 through 9.
01:03But what if you wanted to define only a handful of digits?
01:06Let's just say 1 through 5.
01:09One way to do that would be to type 1, the Or metacharacter, 2, another or
01:14metacharacter, 3 or 4 or 5 and when you click off, that's what you will match,
01:21any of those digits, one or the other.
01:23The problem is the Or Metacharacter is neither the best nor the most
01:27efficient way to do this.
01:29When you use a character set, I'll clear this out here, click off and then go to
01:34the Special Characters menu at the end of the field, go down to the Match
01:39sub-menu and choose Character Set.
01:42That inserts an opening left square bracket and a closing right square bracket.
01:47Anything that exists inside those brackets is part of your character set, so
01:52whatever you put in there is designated to be a valid matching character for
01:57whatever you're looking for.
01:59So within here, I could just type 12345 without an Or metacharacter because
02:05within a character set or is implied. Anything in there is a match so 1 or 2 or 3 or 4 or 5.
02:11So I'll click off here and you can see that the result is the same as we saw
02:16before, without needing the Or metacharacter and just typing in the numbers in succession.
02:21They don't even have to be in that specific order.
02:24It could be any random order of those digits.
02:27This is still yet not the most efficient way of doing this.
02:30Within a character set, there is a way to streamline this even further.
02:35I am going to click in here and I am going to select 2, 3, and 4, delete them
02:40and replace them with a dash.
02:43I'll click off here and you can see that nothing has changed on the page.
02:47I'm still only matching numbers between one and five and nothing above that, but
02:51I'm doing it by describing it as a range of digits from 1 through 5.
02:57And I can do that from 2 through 7 and click off, and you can see what changes
03:03on the page" 2s, 5s, 7s but no 1s, no 8s, no 9s, that sort of thing.
03:09So you can describe a very specific range to suit your needs using this and it
03:13also works on alphabetical characters as well.
03:16So if I typed 'a-z' and clicked off, you'd see I've matched every lowercase letter
03:24from a to z. If I only wanted to match a through k, I could just replace that z
03:30with a k and I only get letters a through k in lowercase.
03:34If I wanted to match a through k in both upper and lowercase, I would just
03:39append A-K after that, within the character set, and I click off and you'll
03:46see those matches here.
03:48C is colored red, A is colored red, O is not and so on.
03:53So this is good for creating a very finite and specific set of characters
03:57that you need to match.
03:58Suppose, however, you needed to describe an actual dash as part of
04:02your character set.
04:03That's one of the characters you want to match.
04:06The safest thing to do when you're doing that is to put the dash at the
04:09beginning of the character set.
04:11For example, if I type 1 through 5 or 1-5 rather, click off.
04:16I'll get a range of digits from 1 through 5.
04:19But if I want to find a dash, a 1 or 5, I'll cut that dash out of there and
04:26paste it at the beginning of the character set.
04:28When I click off, you can see what I match. I matched 1. I matched a 5 and then
04:33down here, in the word 'forty-eight', I matched a dash.
04:36So, whenever you need to include a dash in a character set, the safest bet is to
04:39put it at the beginning of the character set so it doesn't get confused as a
04:43range-definer for any alphanumeric characters that might be around it.
04:47Another thing to be aware of when working with character sets is that certain
04:51metacharacters, specifically the single character metacharacters, like a period
04:56for any character, and a question mark for 0 or 1 times, those characters do not
05:01retain their meaning when they exist inside of a character set.
05:05For example, I'll delete what's in here and click off, and then within
05:10this character set, I am just going to type a period, which normally means any character.
05:15But when I click off, you'll see that it's actually only colored periods on the page, in red.
05:22It no longer means any character.
05:24The same applies for question marks and asterisks and the Plus sign. Any of
05:30those single character metacharacters no longer retain their special meaning.
05:34I always think of it as a character set is like kryptonite on single
05:38character metacharacters.
05:39It just strips them off their special powers and they become the normal
05:43mild-mannered punctuation marks that they normally are.
05:46Other metacharacters, however, act just like you'd expect them to.
05:50If I delete all this out of here and I put in \d for any digit, \u for any
05:57uppercase letter, and click off, I match exactly that.
06:01They're still metacharacters within there.
06:03So if a metacharacter uses the backslash or tilde syntax, and is composed of one
06:08or more characters to define a specific character type, that will still work
06:12inside of a character set.
06:14It's only the single character metacharacters that don't. In fact, there is a
06:18character set built into the Wildcards in InDesign's Special Characters menu.
06:23If I delete this, go to the Special Characters menu and go to Wildcards
06:27and choose Any Letter,
06:29you can see that that's actually a character set.
06:32It's the any lowercase letter and any uppercase letter metacharacters enclosed
06:37within a character set.
06:38It's placed in there as a convenience.
06:40It's not an individual wildcard.
06:42It's two wildcards built into a character set.
06:45So when you need to define several characters as an acceptable match, a
06:49character set is the way to do it.
06:51Remember though, that dashes can define a range of alphanumeric characters and
06:56single character metacharacters lose their meaning inside of a character set and
07:00revert to standard characters.
Collapse this transcript
Using negative character sets
00:00Character sets are typically constructed to describe specific characters you
00:04want to match, but they can also be constructed to do exactly the opposite,
00:08which can sometimes be faster and easier to do.
00:11I'm zoomed in at the top of Page 3, in this document, and my cursor is in the Body
00:16Text Paragraph Style.
00:18I am going to right-click that style name in the Paragraph Styles panel, choose
00:22Edit Body Text and go to the GREP Styles area.
00:25There, I am going to create a New GREP Style and this time I am going to choose
00:28the Yellow Highlight character style that's already built into this document
00:32from the Apply Style menu.
00:34In the To Text field, I am going to click off and clear out that any digit one
00:38or more times metacharacter that goes in by default.
00:42Suppose I wanted to create a character set that described only vowels.
00:47I would start with my opening left square bracket and type 'aeiou' and then I
00:53can do a closing square bracket after that to finish the character set.
00:56Click off here and you can see that's exactly what gets matched, all
01:00the lowercase vowels.
01:02If I wanted it to include uppercase vowels, I could just type 'AEIOU' in uppercase,
01:07within that character set, when I click off that's also reflected and has the
01:12Yellow Highlight style applied to it.
01:14Suppose, however, I wanted to define everything that wasn't a vowel. I can go
01:19into the beginning of this character set and all I need to do is type a caret.
01:24By typing a caret in as the very first character within a character set, the
01:29meaning of that character set changes.
01:31Instead of matching everything that's in the character set, you're matching
01:34everything but what's in the Character Set.
01:37Now you might, at first glance, think that defining everything that's not a vowel
01:41defines only consonants, but let's see what happens when I click off here.
01:45It actually defines all my consonants and none of my vowels, but the yellow
01:49highlight shows that it also includes white spaces.
01:53It also includes punctuation.
01:55It also includes digits.
01:57It's not just any letter that isn't a vowel.
01:59It's anything that isn't a vowel.
02:02So this is something you just want to be aware of.
02:04The scope of a negative character set is anything but what you describe within it.
02:10So to fine-tune this and maybe get it closer to showing me only consonants, if
02:15that's what I need, I can add a few things within the character set that I want to rule out.
02:20For instance, I could put in a \s, which is the any white space
02:24metacharacter. Click off here and you'll see that white spaces are no
02:28longer highlighted.
02:29I can add a few other things like a comma, a period, a quotation mark and a dash,
02:35and let's click off and see what happens there.
02:37It no longer highlights any of those.
02:40So, as I whittle away and add a few more things that narrow this down, I'm no
02:44longer getting all those unwanted matches.
02:47So, while negative character sets describe what you want left out, always
02:52remember that they then include everything else and you may need to adjust that
02:56negative character set to rein in its scope and define precisely what you want.
Collapse this transcript
Finding around text with lookbehind and lookahead
00:00The remaining metacharacters under the Match submenu are all related and very
00:04similar, once you can get past their very cryptic names.
00:08These are Positive Lookbehind, Negative Lookbehind, Positive Lookahead,
00:12and Negative Lookahead.
00:14Despite those names, which were clearly written for computer programmers, these
00:18metacharacters are not only simple to understand, they're essential for many
00:22GREP styles and searches.
00:24I'm on page 2 of this document, zoomed in towards the bottom of the page and
00:28my cursor is within the Body Copy text, which is highlighted in the Paragraph Styles panel.
00:34In this text, there are a number of figure references, up here there is Figure
00:375, down here there's Figure 6 and there are others throughout the document.
00:41What I want to do is apply a character style only to the figure references
00:46themselves, so that they stand out from the rest of the body copy.
00:50To do that, I am going to modify this Body Copy style with a GREP style.
00:53I'll right-click the style name, choose Edit Body Copy and go to GREP Style area
00:58of this Paragraph Styles Options dialog.
01:01I'll create a new GREP style and I am going to pick an existing style from the
01:05Apply Style menu called Figure References.
01:08And that applies a different color, typeface, and some other variations to the
01:12text that will standout on the page.
01:14I am going to clear out the default of any digit one or more times, but it does
01:18give you a preview, here in Figure 5, Figure 6, of what that style looks like.
01:23I'll get rid of that default and click off and I am going to start defining what
01:27my figure references look like.
01:29Essentially, they all follow the form figure, space, and a digit.
01:33It could be one digit. It could be more.
01:35So I am just going to type in the literal text Figure space, and then from a
01:40Wildcard submenu, choose Any Digit and then from the Repeat submenu, choose One or More Times.
01:47So I have described Figure space any digit one or more times and I'll click off
01:52here and we'll see what we get.
01:54And it's done a good job of highlighting Figure 5, Figure 6 and applying that style.
01:59But there's a small problem and it's actually down here.
02:02As shown in Figure 6, this is a figure reference that appears within the Body
02:07Copy not enclosed inside a parenthesis, and stylistically that's not what I want
02:12to highlighted, I only want the first instance of all of the figure references
02:16that exist within parenthesis to be highlighted.
02:19So let's try and solve this problem.
02:21If I just add parentheses around this existing expression, which, in order to do
02:27so I need to either choose the Open Parenthesis Character from the Symbol
02:31submenu, which puts in an escaped out opening parenthesis.
02:35It's preceded by a backslash or I could just type that in myself backslash open
02:40parenthesis and at the end of the expression, I'll type in backslash close
02:44parenthesis to describe an actual parenthesis character.
02:49When I click off, I've solved the problem down here, with Figure 6 being
02:53highlighted when it's not enclosed in parenthesis, but I've introduced another problem.
02:58The parentheses themselves also get the style applied to it and that's not what I want.
03:04I want the text inside the parentheses to be styled, but not the parentheses
03:08themselves and my double challenge is I need the parentheses to describe which
03:13particular figure references I want highlighted.
03:16In order to accomplish this, I need to use Positive Lookbehind and
03:21Positive Lookahead.
03:23What those two metacharacters do is impose a condition that requires something
03:28to exist before the text I'm describing, which is Positive Lookbehind, and
03:33something to exist after the text I am describing, which is Positive Lookahead.
03:38One looks before the text, one looks after it.
03:40If the parameters that I describe as required to be there are there, it's a match.
03:45If they're not, it's not a match.
03:47So let's see how that's setup.
03:49I am going to get rid of the opening parenthesis and the closing parenthesis and
03:55we can see our problem with Figure 6 is reintroduced.
03:59I'll put my cursor right at the beginning of this expression, I am going to
04:02go to the Special characters menu to the Match submenu and choose Positive Lookbehind.
04:08I need to look before this word 'Figure' for an opening parenthesis.
04:14This is the syntax for Positive Lookbehind, an opening parenthesis, a question
04:17mark, a less than sign and an equal sign.
04:21After that equal sign is where I enter what must be there, and what must be
04:26there is an opening parenthesis, which I still have to escape out with a
04:30backslash character.
04:32So I am saying an opening parenthesis character must exist before the word
04:36'Figure', but because it's just looking for it, it will not have the style applied to it.
04:43On the other side of the expression, I'm going to use Positive Lookahead, which
04:46looks after the expression to ensure that something I define exists.
04:52So from the Match menu, I'll choose Positive Lookahead and it puts in a slightly
04:57shorter syntax opening parenthesis, question mark, equal sign and after the
05:02equal sign, I will type in my backslash closing parenthesis.
05:07So I've defined the figure reference itself and imposed a condition that it
05:10must be preceded by the opening parenthesis and it must be followed by the
05:14closing parenthesis.
05:16However, the only part of this that's going to get the style applied is this,
05:22Figure and whatever the figure number is.
05:25Let's see if that's successful.
05:26I'll click off on the page and you can see that's exactly what I get.
05:30It has solved all my problems.
05:32The text inside the parenthesis is styled, here in Figure 5 and here in Figure 6,
05:37but since this Figure 6 is not meeting the criteria for being surrounded by
05:42parenthesis, it's ignored and the GREP Style is not applied.
05:46Now Negative Lookbehind and Lookahead do exactly the opposite of their
05:50Positive counterparts.
05:51They both look either before or after, behind or ahead of the text in question,
05:57but they establish a condition that the match is only valid if those things I
06:01define are not there.
06:03So let's try that out.
06:04Suppose we're trying to do exactly the opposite of what we just did, and I only
06:09want to define this Figure 6, that's not in parenthesis, and make sure that any of
06:14the figure references that are in parenthesis don't get styled.
06:17I am going to reduce this expression down, eliminating the Positive Lookahead
06:23and Lookbehind portions of it.
06:25I'll click off here so we can see what happens.
06:27Again, I've styled all of the figure references with no criteria imposed on them
06:33and in the end, I only want to have Figure 6 down here, styled.
06:37So I'll put my cursor at the beginning of this expression, go to the Special
06:40characters menu, go down to Match and choose Negative Lookbehind, so it's going
06:47to look before this text and make sure that whatever I define is not there.
06:51Here, after the exclamation point, but before the closing parenthesis, I am
06:55going to put in an escaped out opening parenthesis backslash opening
06:59parenthesis.
07:01At the end of the expression, I'll again go to this menu, go to Match and choose
07:06Negative Lookahead. Look after this text, make sure what I specify is not there.
07:12Put my cursor in right before the closing parenthesis and I'm going to type in
07:16an escaped out closing parenthesis, backslash, closing parenthesis.
07:21Let's click off here and see what happens. Exactly, what I wanted.
07:25I've imposed the condition that if you find a figure reference and it has
07:29parenthesis around it, ignore it, but if you find one that doesn't, apply the style.
07:34There is one important limitation to note about both Positive Lookbehind and
07:39Negative Lookbehind.
07:40None of those will accept any of the repeat metacharacters, such as the plus
07:44sign, question mark, or asterisk.
07:47Lookahead and Lookbehind, whether you use the positive or negative variety, allow
07:52you to define, with great accuracy, something that must or must not exist around
07:56the text you're describing, in order for it to be a match.
Collapse this transcript
Building with modifiers: Case sensitivity
00:00The next few modifiers we are going to look at are grouped under the Modifiers
00:04sub menu because they modify how GREP behaves.
00:07GREP has certain default behaviors, such as case-sensitivity, and the
00:11metacharacters in this sub menu allow you to change some of those defaults.
00:15Let's start with case-sensitivity.
00:17I am on page 10 of this document and I want to build a GREP expression that
00:21searches for the word 'king', regardless of case.
00:25So, with my cursor in the body text, I'll right-click on the Style name
00:29Body Text in the Paragraph Styles panel, choose Edit "Body Text", go to GREP
00:34Style, and I am going to create a New GREP Style for this purpose.
00:38From the Apply Style menu, I am going to choose my Red character style again.
00:43That turns my text red, and clear out this default.
00:46I want to look for the word 'king' with case-sensitivity turned off.
00:50First let's see what happens if I just type in king and click off here.
00:54It matches 'king', in lowercase here, but it's also going to match any partial word
01:00'king' as in 'thinking' or 'kingdom', and I may not want that.
01:03So let's say I put a word boundary character at the beginning, which is
01:09\b, and a word boundary character at the end, so I'll only find the
01:14word 'king' by itself.
01:16It's still finding only lowercase king because that's how GREP behaves.
01:20But over here, I have King with an initial cap K, and I want to make sure that I find that too.
01:26So what I need to do is change GREP's behavior, which is to always be
01:30case-sensitive, by using a metacharacter, which I need to place right at the
01:34beginning of this expression.
01:37From the Special Characters menu, I'll go to Modifiers and choose
01:41Case-insensitive On.
01:43This is another poor choice of words in terms of making this clear for people to understand.
01:48Since GREP is Case-sensitive, you have to make it Case-insensitive and you are
01:54turning that Insensitivity on.
01:56It's awkwardly phrased, but that's exactly what it means.
01:59So I'll choose Case-insensitive on, which means case is no longer required in
02:04this for it to be a match, and I'll click Off here and you can see that it finds
02:08the lowercase kings that were there before, but also the king with initial caps.
02:14So I am going to click OK here, and that's how I turn case-sensitivity off for
02:18any portion of an expression.
02:21If I only need it for a small part of an expression, I can always turn it on later.
02:25For example, further up in this document, there is the word KING, in all caps,
02:32and let's say, for some reason, I didn't want king in all caps, I only want king
02:37in lowercase, like it is here, King with an initial cap K, but not KING with all caps.
02:44Since I've made it case-insensitive, it's going to find all three.
02:48So I can affectively switch case-sensitivity back on at any point in an
02:52expression, if I want.
02:54I'll go back to the Style Options for this body text, to the GREP Style that
02:59I created earlier, and I am going to modify this right after the k in the expression.
03:05I'll put my cursor, go back to this menu, down to Modifiers and I'll turn
03:10Case-insensitive off, which translated for normal people means
03:14case-sensitive, and I'll insert that in and that's the metacharacter that
03:19resumes case-sensitivity.
03:21I'll click off here, and it jumps me back, unfortunately, to the part of the
03:26page where my cursor was before, but I'll click OK.
03:29And I'll just go back up to the second page where we have that and there is 'king'
03:34in lowercase, 'King' with an initial cap, but 'KING' in all caps is not a match,
03:40because case-sensitivity was switched back on.
03:42You never know how consistently some of the text you are working with has been typed.
03:47Text comes from many places and people make mistakes, so if you think that there
03:50is a chance that what you are trying to define might not have all been typed in
03:54the same case, this is one way to avoid a specific type of GREP behavior.
Collapse this transcript
Building with modifiers: Single-line and multi-line
00:00The Single-line and Multi-line options change another default behavior of GREP,
00:04which is to treat each paragraph individually.
00:08The parameters of a search automatically end when a hard return is encountered
00:12at the end of a paragraph.
00:13This is what's called Multi- line mode and it is on by default.
00:17Changing from Multi-line mode to Single-line mode only affects one thing,
00:22how GREP treats the Beginning of paragraph metacharacter and the end of
00:26paragraph metacharacter.
00:28Let's take a look at what this means.
00:29I am going to open the Find/Change dialog by hitting Command+F, or Ctrl+F on
00:34Windows. I am in the GREP tab and if I were to describe a paragraph,
00:39it would essentially be the location, the beginning of a paragraph, then any
00:44character One or More Times and then the location, the end of a paragraph.
00:48Typically, the way that GREP works, I don't really have to define the beginning
00:53and end of a paragraph if I am using something like the Any Character
00:57metacharacter, which is a period, followed by a plus, meaning One or More Times.
01:02If I just put that in Find What and click Find, it finds this paragraph and it
01:08stops as soon as it encounters a hard return, which is the only thing not matched
01:12by the any character metacharacter.
01:14If I click Find Next, I will find the next paragraph and it stops there and so on and so on.
01:20It considers each paragraph to be a separate line, so it is working in what
01:25is called Multi-lines.
01:27Paragraphs are multiple lines and it treats them that way.
01:31In the Single-line mode, the hard return at the end of the paragraph does not
01:35stop the any character metacharacter.
01:39Let's us take a look at how that works.
01:40I am going to go at the beginning of this expression and then go over to the
01:45Special characters for search menu and down to the Modifiers menu and turn
01:50Single-line on by choosing Single-line On from the list.
01:55That puts in this metacharacter at the beginning of my expression and I am going
02:00to click Find Next, then let's see what we get.
02:02It's completely different in terms of how it treats the return at the end of the line.
02:07It is not treating every paragraph as multiple lines.
02:10It is treating the entire story, beginning to end, as a single-line.
02:15This is really the only difference.
02:16This is the only thing this does.
02:19If, at some point, I want to add to this expression and go back to Multi-line
02:22mode, I would just choose Multi-line On from the Modifier submenu and revert
02:29back to the default behavior.
02:31But basically, this is all this does.
02:33It just treats the beginning of a paragraph as the beginning of a whole story
02:38and the end of a paragraph as the end of the story and it ignores all the
02:42paragraphs in between.
02:44Personally, I've never found a use for either of these metacharacters in a
02:47real world situation.
02:48Their purpose is so specific and limited that it's just never come up.
02:52The fact that they're only applicable to GREP Find/Change and not GREP styles
02:56is yet another limitation, because GREP styles only work within specific paragraphs.
03:02So even if you turn these options on a GREP style, they'd essentially be
03:05meaningless, because the style will stop looking at the end of each paragraph.
Collapse this transcript
Using InDesign-compatible Posix expressions
00:00The last grouping of metacharacters in the Special characters menu are the
00:04Posix metacharacters.
00:06Posix stands for Portable Operating System Interface and it's a form of writing
00:10expressions that's slightly different from what we've seen so far.
00:13So let's take a look at the difference between Posix and some of what we've seen so far.
00:17I am on page 3 of this document and my cursor is within the Body Text paragraph style.
00:23I am going to right-click on that style name, choose Edit Body Text from the
00:27Context menu and in the Paragraph Style options, I will switch to GREP style.
00:31I am going to create a new GREP style just so we can gain access to this menu at
00:36the end of the To text field and take a look at the Posix metacharacters.
00:40Down at the bottom of the list is Posix and there are a handful of
00:44metacharacters here that are a different form of Wildcard.
00:48Many of them overlap Wildcards we've already seen in this menu.
00:53So they're repetitive and just a different way of saying something we've already
00:57covered in previous movies.
00:59However, there are a couple of Posix meta- characters that could prove very useful.
01:02I will just quickly go down the list.
01:04They're named slightly differently, so it's a little bit easier to figure out
01:08what a Posix metacharacter means just by looking at it.
01:11The first one alnum is any alphanumeric character, so any upper or lowercase
01:17letter or any digit.
01:18Alpha is any alphabetical character, upper or lowercase.
01:22Digit is any digit. Lower is any lowercase character. Punct is any
01:27punctuation character. Space is any white space. Upper is any uppercase
01:32character. Word is any word character.
01:34So this is a lot of overlap between Wildcards we've seen in previous movies.
01:38The only thing that's unique here, at this point is punct, which specifies
01:44punctuation in one fell swoop.
01:46You don't have to create a character set that includes every possible bit of punctuation.
01:51It's automatically handled by this Posix metacharacter.
01:54So that's a very useful one.
01:56The next one down here, xdigit, this speaks to the computer programming origins
02:01of GREP in general and certainly of Posix.
02:03It refers to any hexadecimal digits.
02:06So it is placed inside of a page layout application.
02:08It doesn't really reveal itself, I don't think, for most of us.
02:12But if you use hexadecimal digits in your documents for some reason and want to
02:15apply GREP style to them, this is the metacharacter for you.
02:19The last Posix metacharacter is even different than all the other ones, which are
02:24different from the metacharacter syntax we've seen so far and the example in
02:30this list is just two opening square brackets an equal sign the letter A and
02:35another equal sign and two closing square brackets.
02:38Let's take a quick look at this one, just so we can understand what it is.
02:42As it appeared in the menu with the A, that is just a visual cue for your
02:45benefit of the syntax for this type of metacharacter.
02:49If I actually type in 'a' here and then, from the Apply Style menu, I choose my
02:55Red character style.
02:56Let's take a look at what this does on the page.
03:00I will click off here and notice that it has matched every lowercase A and every
03:05uppercase A. Beyond that, and what you can't see here, because there are no
03:09instances of it, is that it will also match every accented A. Everything with an
03:14accent grave, everything with an accent acute, any variation, any equivalent of
03:20an A that's defined by that typeface is going to be matched by this character.
03:26So it's very broad if you're working with text that has a lot of accented
03:29characters and you need to account for every variation of A or every variation
03:33of an accented vowel or any character with multiple variations, this is the way to do it.
03:38It's also a way to account for, at a minimum, both upper and lowercase
03:42instances of that letter.
03:43The same would apply if it was C, upper and lowercase C's and the accented C's and so on.
03:49So whatever you put in there any single character, you're going to get every
03:52variation for that character.
03:55So that's a unique Posix metacharacter that's very useful.
03:58I am going to clear that out here and the other Posix metacharacter I mentioned
04:03earlier as being unique to Posix, and very useful, is the punct Posix
04:09metacharacter, which accounts for all punctuation, and there is an example from a
04:13previous movie where we were constructing negative character classes to find
04:17anything that's not a vowel.
04:19If the goal was actually to find only consonants, defining a negative
04:23character class as anything that isn't a vowel grabbed up a lot more text than we intended.
04:28It grabbed punctuation and white spaces and any number of other things.
04:32So let's reconstruct that character set using an opening square bracket, the
04:37carrot symbol, which means match everything in this character set that isn't
04:41what I type following this symbol.
04:43And we put in 'aeiou' and, in uppercase, 'AEIOU' and close that off with a
04:50closing square bracket.
04:51That's a negative character set that says find anything that is not an upper
04:55or lowercase vowel.
04:56I am going to change the character style to yellow highlight because that's the
05:00only way I can see the white spaces that it finds as well.
05:04This is what we've found.
05:05It excluded vowels, but included every single other type of character.
05:10If I were to try to eliminate all of the punctuation, I'd have to remember every
05:14potential punctuation mark there is in the alphabet.
05:18That's not time well spent on my part, so I can take advantage of that
05:23punctuation Posix metacharacter and include it inside of this character class,
05:28along with these standard characters.
05:30So, I am going to the Special characters menu, down to Posix and pick that
05:35punct metacharacter.
05:37Now there is one problem that I am going to reveal, before we even click off here.
05:41All Posix metacharacters are in fact character classes already.
05:45They have two square brackets on either side of the expression and when they're
05:49just used by themselves, that's fine.
05:51That's exactly how they're supposed to appear. But if you put a Posix character
05:55inside of a character class, you need to get rid of that extra square bracket at
06:00the end and the extra square bracket at the beginning.
06:04When I do that and click off here, notice all my punctuation has been deselected
06:09because I've defined punctuation, any form of punctuation, as something to be
06:13skipped over and that makes this easier to define.
06:17Now I can put in any white space and eliminate that.
06:21At this point, I've now described every consonant and the punctuation
06:25metacharacter made it much quicker and easier to do.
06:28So even though Posix expressions are all the way at the bottom of the menu,
06:32don't follow the same syntax as most of the other metacharacters we've seen and
06:37often repeat the functionality of many Wildcards, these punctuation and
06:42character equivalent Posix expressions, in this list, are hidden gems that
06:46describe character sets that are otherwise very difficult to describe with
06:50conventional metacharacters.
Collapse this transcript
4. GREP Styles
GREP styles vs. nested styles
00:00If you're familiar with, or have used Nested Styles, which have been around
00:04since InDesign CS, you may be wondering what the specific advantages of GREP
00:08Styles are versus Nested Styles.
00:11Nested Styles are powerful and very easy to use, but they do have certain
00:15limits and once you reach those limits and need to do more, you need to use GREP Styles.
00:21Let's take a look at the basic differences between one and the other.
00:25In this document, there are a number of Embassy listings and for each there is a phone and fax.
00:31The line with the phone and the line with the fax, each start with a Nested
00:35Style, that styles the word Phone and the colon, the word Fax and the colon,
00:40differently from the rest of the line and it does it automatically.
00:43I am going to put my cursor in one of those styles.
00:46Open the Paragraph Styles panel and we can see the Fax style is selected.
00:52So, I am going to right-click on that and choose Edit Fax.
00:55I will go to Drop Caps and Nested Styles and in the Nested Styles area, you
01:00can see there is a character style called Phone and Fax Lead-Ins that's
01:06automatically applied through one colon, and that's how this automatic styling is accomplished.
01:13In the Phone style, it's set up exactly the same way.
01:16Now, this is very convenient and easy.
01:19You pick a style from this list.
01:23You choose how far that style extends, through or up to a specific number of an
01:29ending criteria, at the end.
01:31So, it's very simple, structured and easy to use, but that structure is very rigid.
01:37All Nested Styles start at the beginning of a paragraph and they have to follow
01:42a very rigid uniform path through the paragraph.
01:47Any variation from that and the style will not work as intended.
01:50Now you can easily re-create this exact same functionality in a GREP style.
01:55In fact, I am going to do that very quickly here.
01:57I am going to delete this Nested Style and you can see that fax is no longer
02:03styled in any of these paragraphs the way it was before.
02:06Now, I am going to do the exact same thing with a GREP style.
02:09I am going to create a new GREP style and I am going to apply the style
02:16Phone and Fax Lead-Ins.
02:19When I click on here and notice it's highlighted, Any digit One or More Times,
02:23and not what I want.
02:24And if I am structuring this, much the same way as a Nested Style thinks about
02:28it, a Nested Style would consider this whole style to start at the beginning of a paragraph.
02:34So, I will choose the Location metacharacter>Beginning of a Paragraph and then
02:39after that I can type the word Fax and a colon and click off here.
02:44That's one way to do it.
02:46I could also type the Any Character metacharacter and then One or More Times
02:51followed by a colon.
02:53That accomplishes the same thing.
02:55There are a few different methods for doing it in GREP, but depending on what
02:59you're comfortable with, this is no more or less effective than doing a Nested Style.
03:03Picking them from the list in Nested Styles is quite easy and if a Nested Style
03:07gets the job done for you, then by all means use a Nested Style.
03:11But unless there is a rigid structure that is uniform across the entire
03:15paragraph, a Nested Style is not going to adapt to unpredictable situations,
03:22the way that GREP can.
03:23And there is an example of what I mean, right here, in this paragraph.
03:26This Ambassador's name is an Arabic name that begins with al hyphen and
03:32because InDesign allows even text with hyphenation turned off to hyphenate at
03:39a typed dash this name, which is a proper name, is being hyphenated and that's
03:44just not appropriate.
03:45It should all be on one line.
03:47So, I want to account for any instance of any of these names that start with al-
03:53and apply a No Break attribute to them.
03:56And this is not something I can do with a Nested Style because I don't know
04:00where this is going to occur in the paragraph. I can't set up a rigid structure.
04:05So, I am going to cancel out of this and I am going to put my cursor in this
04:09line and it highlights the Ambassador paragraph style, in the Paragraph Styles panel.
04:14I will right-click on that, choose Edit Ambassador and I am going to go to GREP
04:19styles and create a new GREP style to fix this problem.
04:23I am going to click New GREP Style here and from the Apply Style menu, I am
04:29going to choose an existing Character Style out of this list called No Break.
04:33The only thing this does is apply the No Break attribute.
04:36Everything else about the Typeface, Color, Size is left undefined.
04:41And what I want that applied to it is the Beginning of a Word from the
04:48Locations submenu, followed by al- and then Any Character, so I will type a
04:55period for Any character, because I don't know what's necessarily going to
04:59follow the beginning of that surname.
05:01I'll click off here and let's see what we get. Beautiful!
05:06It has kept those two together that name will not break and no other instance of
05:11that name will break anywhere else.
05:13And I haven't had to define where it falls within the paragraph.
05:17I just want to make sure that it's at the Beginning of a Word, so that's why I
05:21included the Beginning of Word metacharacter.
05:23Let's take a look at how well this has fixed the problem document wide.
05:27I am going to go all the way to the end of this story and just move over here
05:32because I happen to know that there is an instance of this also under Yemen.
05:38This is another name that starts with al-, but it continues on with a different
05:42letter following it.
05:44And it has fixed this too.
05:45I am going to actually select these letters and go up to the Control panel and
05:51you can see that the No Break attribute is applied to this and it was done
05:55dynamically by the GREP style.
05:58This is something that a Nested Style simply can't do because of its
06:02specific order and limited set of rules, but a GREP style can because it has
06:07no such limitations.
Collapse this transcript
Styling specific words or phrases
00:00Another advantage of GREP Styles over Nested Styles is that a GREP Style can
00:04be applied to specific words or phrases, no matter how many times they appear in a paragraph.
00:09This is an ideal way to automatically italicize, for instance, a publication
00:13name, or highlight a product name, and it's one of the easiest GREP styles
00:18you'll ever create.
00:19In this paragraph, there are a number of different product names and I want
00:22to highlight one in particular, the Super Widget product name, in a different Character Style.
00:28And I want to do that everywhere it appears and I don't want to do it manually.
00:32So, in order to have it done automatically for me, I am going to create a new
00:35GREP style in this product description Paragraph Style.
00:38I will right-click that style name in the Paragraph Styles panel, choose Edit
00:42Product Description and go to GREP Style to create a New GREP Style.
00:48The style I want to apply is already in this document.
00:51It's called Product Name and I will just pick that from the Apply Style menu.
00:55And the text that I want to apply it to is the actual product name.
00:59This is literal text, no metacharacters involved.
01:01I am just going to type 'Super Widget'.
01:05When I click off here, you'll see not only the first instance, but the second
01:09instance of Super Widget is in there.
01:11And if I typed it 10 more times, it would also appear there.
01:15If I typed just the word 'Super', it would not style it. If I typed just the word
01:19'Widget', it would not style it.
01:21So, this is specific to this presentation of this product name.
01:26Nested styles simply can't do that.
01:29If I were to try to accomplish this with a Nested Style by creating a
01:32new Nested Style, choosing that same Style Name, first of all, I run into the
01:38problem with a criteria that I have to determine a specific amount that I have to indicate.
01:45And anything I type in this field, if I type the word 'Super', a Nested Style
01:50doesn't see the word Super, it sees a choice, either an uppercase S, or a
01:55lowercase u, or a lowercase p, or a lowercase e, or a lowercase r. Whichever one
02:00comes first, it considers it a match.
02:02So, there is no way to describe a word at all with a Nested Style.
02:06So, this is just never going to work.
02:09A GREP Style is the only way to do it.
02:11If I want to get ambitious and highlight all of my product names, I can
02:15certainly create a new GREP Style using the same Product Name style and add
02:20the names of one of the other products in this paragraph, like Wonder tool and it will do that.
02:28And I could create another one for any other products that are in there, or I
02:33could be a little bit more efficient.
02:34Delete this style and instead, expand the definition of this GREP Style with the
02:42Or metacharacter by choosing Match, Or and then typing in 'Wonder Tool'.
02:50And then another Or metacharacter and Miracle Product.
02:55I would click off here, click OK and in one GREP Style, I've highlighted
03:00multiple instances of multiple Product Names.
03:04This particular GREP style only uses one metacharacter, the Or metacharacter and
03:09that's only because multiple product names are specified.
03:12The rest is all plain text making this one of the simplest, yet very useful GREP
03:16styles you could ever create.
Collapse this transcript
Describing inconsistent text
00:00When text is 100% consistent, it's very easy to describe.
00:04Inconsistent text is a bit more challenging, but can also be described with GREP.
00:08In a previous movie, we set up a GREP style that automatically formatted
00:12figure references in a document, and it successfully formatted only the figure
00:18references that appear in parentheses, not the ones that didn't, but excluded
00:22the parentheses from the formatting, using Positive Lookbehind and Positive Lookahead.
00:27This is that document with that style applied.
00:30I am on page 4, and as I scroll down, I can see my styled Figure 11 reference,
00:36and down here later on the page, I see Figure 14 and Figure 15.
00:41So something is missing.
00:43Something didn't get styled.
00:44I will scroll back up, and you can see here, Figures 12 and 15.
00:49They are not referred to in a consistent manner, as the other figures.
00:54Let's take a look at the Paragraph style itself, and the GREP style built into
00:58it to see what we've got so far.
01:00I'll choose Edit>Auto Figure References, and go to the GREP Style area for that style.
01:07And here's the expression we set up in the previous movie.
01:10Positive Lookbehind and Lookahead are at the beginning and end of the
01:13expression, and we refer to all of the figure references as Figure, space, any
01:19digit one or more times.
01:20Well, this Figures 12 and 15 out here does not meet that criteria.
01:25It doesn't match, so it isn't styled.
01:28So I need to modify this GREP expression.
01:30So that I'll not only continue to style the figure references that I've already
01:34styled, but to account for this slightly different phrasing of figure references
01:40here, where I refer to more than one figure.
01:43The first thing I need to do is account for the presence of the plural version of 'figures'.
01:49That's easy enough to do by just putting an S at the end of the word Figure,
01:54then going to the Special Characters menu, and choosing the Repeat
01:58Metacharacter Zero or One Time.
02:02This means the S may be there.
02:04It may not be there. Both are a match.
02:08And if I click off here, let's scroll back down to that. That has not yet fixed
02:13this, because it's only fixed one part, Figure and Figures,
02:17but what follows that is still not described in a way that handles both.
02:21So the thing you need to do when you're working out of GREP expression is to
02:25step back, and look at what it is you are trying to describe, not get too hung
02:29up on the specifics of the words themselves, and think about the pattern
02:33you're trying to describe.
02:35So, in this instance, I'm trying to account for the word 'Figure' or 'Figures', which
02:41I've already done, followed by a space, followed by any digit one or more times.
02:47That gets me all the way through Figures, space 12, in this
02:53particular figure reference.
02:54I have to account for the possibility that another space, another word, another
03:00space, and another one or more digits could follow that before the closing
03:05parenthesis is encountered.
03:07There are a couple of ways that I can do this.
03:10Some of them are very rigid and specific.
03:13Some of them are far more flexible.
03:15Let's start with what might be the natural inclination.
03:19After the any digit One or More Times Metacharacter, I could type in a space,
03:24the word 'and', another space, and another any digit one or more times
03:30metacharacter combination.
03:32If I enclose that in parentheses, making it a sub-expression, and then follow it
03:42with a question mark, meaning zero or more times, I've now made the presence of
03:49the word 'and', the spaces around it, and the additional number optional.
03:53So I am going to click off here, and I'll see what that does.
03:57That solved the problem,
04:00but it solved the problem in a very, very specific way.
04:04So I am going to click OK here, and commit to this style.
04:08Let me make a change.
04:10Instead of 'and', at some point this document is edited, and it becomes an
04:15ampersand and my automatic styling breaks.
04:19My other styles still work. Figure 11, Figures 14 and 15, no problems there.
04:26But I've been a little too rigid and not accounted for the fact that things
04:30change and maybe I should write an expression that's a little bit more
04:34flexible, and adaptable.
04:35So I am going to go back in and modify this style again.
04:39And in this GREP Style, I don't want to think specifically about the word 'And'
04:47and I want to cover my bases as much as possible.
04:50Suppose this was phrased as Figures 12 through 15, which it technically should
04:57be because figures 12 and 15 are nonconsecutive.
05:01But if it was going to be Figures 12 through 15, or 12 em dash 15, however it's
05:07going to be phrased, I want to account for any possibility of that.
05:11So the 'And' is a little bit too specific for me.
05:15So I can get rid of that, and instead, I'm going to replace that with something
05:20more broad, and less specific.
05:22From the Special Characters menu, I'm going to choose the Wildcard, Any
05:28Character, and after that, the Repeat Metacharacter, One or More Times(Shortest
05:36Match), because technically, the numbers in the second figure reference also fall
05:42under the criteria of any character.
05:45If I just use One or More Times, it's not going to differentiate, and it's going
05:49to go straight through to that closing parenthesis.
05:51So this makes things more specific and reins in that any
05:56character metacharacter.
05:57So I'll choose that, and it puts in a Plus sign and Question Mark, which is One
06:02or More Times(Shortest Match).
06:04I'll click off here, and there we have a successful match.
06:08Let's test out just how successful it is.
06:11Click OK. I'll select this ampersand, and instead, I'll type the word 'through',
06:19Figures 12 through 15. That also works.
06:23If I get rid of the spaces around it altogether, and type in an em dash,
06:27Figures 12-15 also work.
06:31So, this works for many, many phrasings of a figure reference, and I have got a
06:36very flexible style that I can use
06:38that's going to account for all of them.
06:40So I've covered all the bases.
06:42All the figure references within parentheses are styled, but the parentheses
06:45around them are not, and in those instances, where the wording of those
06:49references varies from most of the others, we've allowed for that using the Zero
06:54or One Times Metacharacter, and making certain parts of the expression optional.
Collapse this transcript
Describing and styling prices
00:00Another useful GREP style to have on hand is one that finds and formats any price
00:05within some text in order to highlight it.
00:08Describing a price is pretty straightforward,
00:10but there are some things to look out for, and a few tips that can help make the task easier.
00:16In this text, there are a handful of prices, some in parentheses, some not, some
00:21with cents at the end, and some not.
00:24I want to create a GREP style within this Body Text that automatically applies
00:29the OpenType Proportional Oldstyle figure style to the numbers in a price.
00:35I don't want it to apply to any number, for instance, the 7 here in 7.0 and the 3 in CS3.
00:42I want to limit it to just prices.
00:45So I need to describe prices exactly as GREP needs to understand them, to make them unique.
00:51In this Body Text style, I'm going to right-click the Body Text style in the
00:55Paragraph Styles panel, choose Edit "Body Text", go to GREP Style.
01:01This style already has a GREP style in it, the one for figure references that
01:06was used in a previous movie.
01:08That's not a problem.
01:09I can have multiple GREP styles within one Paragraph Style.
01:12I'm going to create a New GREP style.
01:15It gets added beneath the existing GREP style.
01:19For that, I'm going to choose the OT Proportional Oldstyle character style
01:25that's in this document from the Apply Style menu.
01:28What I want it to apply to is not any digit one or more times, which is the default.
01:34I'll clear that out, but you can see it's already started to highlight digits,
01:37including some that I don't want.
01:39I'll clear that out so we're starting fresh and let's start describing a price.
01:46The first part of a US price is, of course, the dollar sign.
01:50However, the dollar sign has a whole another meaning, where GREP is concerned.
01:54The dollar sign means the end of a paragraph.
01:58So if I want to describe an actual dollar sign, I need to escape that out first with
02:03a backslash, then type my dollar sign.
02:05I'm going to click off here, and see that we've got a match, all dollar signs are found.
02:11So we're off to a good start.
02:14If you're thinking about a price in general terms, you could think of it as a
02:17dollar sign followed by any one or more digits, followed by a decimal point,
02:23followed by any two digits.
02:25So let's start building that expression.
02:27I'm going to put in /d, for any digit, plus, for one or more times.
02:33That should describe the dollar value, Then the period that separates it.
02:37The decimal point, I can't put in by itself, because a period means any character.
02:41So I'll escape that out with a backslash first, so backslash, period
02:46describes an actual period.
02:48That's then followed by any digit, and I could say, one or more times with the plus
02:54character, but a more specific way would be to do an opening brace character,
03:01the number 2 and a closing brace character, to describe exactly two digits.
03:06Similarly, I could just type a second Any Digit metacharacter. There is no right
03:10or wrong about it. Those methods all work.
03:13So now I've described a price, or, at least, I think I have.
03:16I just click off here, and see what I get.
03:20Now I don't even have my dollar signs matched, something has gone wrong.
03:23The problem is that I haven't accounted for a couple of things.
03:28I haven't accounted for the fact that the numbers in thousands include a comma
03:33in the price, or for the fact that at the end of this sentence, the price $699,
03:39which technically should match, doesn't match, because it doesn't have two
03:44digits after the decimal point.
03:47So I need to restructure this description of a price, which at first seemed so
03:52simple, but now we can see it has a few complications.
03:55The first is to change that problem with the numbers in thousands.
04:00Any Digit, one or more times does not account for the presence of a comma in that number.
04:05So instead of just that Any Digit metacharacter and the Repeat metacharacter
04:09that follows it, I need to create a character set.
04:13From the Special Characters menu, I'm going to choose Match, Character Set and
04:19that puts in my opening and closing square brackets.
04:22In there, I'm going to define a character set that consists of Any Digit, \d, or a comma.
04:29That accounts for the fact that a comma could be in that number.
04:32Outside of the character class, to the right of the closing square bracket, I'll
04:38put my one or more times metacharacter, the plus sign.
04:42That now means one or more of either a digit or a comma.
04:47I'll click off here and see what I get.
04:49Well, almost there, I've got $1,799 here $2,499 here.
04:54I've solved my problem with numbers in thousands,
04:57but I still haven't solved the problem that not every price in here actually
05:02uses cents at the end.
05:05So let's deal with that.
05:07The way this GREP expression is structured now, the period and the two
05:11digits are required.
05:13However, if I want to make those optional, all I need to do is enclose that
05:17whole portion of the price that describes the decimal point and the cents within
05:22parentheses, which makes it a subexpression.
05:26So I'll put an open parenthesis before the backslash, period, and a closing
05:30parenthesis after the any two digits metacharacter combination.
05:35That isolates that part of the expression, and it will now be thought of as a
05:39self-contained whole.
05:41So when I add the zero or one time metacharacter at the end of it, meaning it's optional,
05:49it could be there, it could not be there,
05:51it applies to the entire subexpression, the period and the two digits.
05:56So I'll click off here and there we go.
05:59I've built an expression that describes all of these prices and applies the
06:04appropriate style to them.
06:06I'm going to click OK to save this style and point out one other aspect of
06:10this GREP expression that's very handy.
06:13If for some reason, someone decides that the commas have to come out, and they
06:17don't want them in the prices, I can delete them wherever they appear, but my
06:22style doesn't break.
06:24The character set has defined any one or more digits, or any comma, one or more
06:31times, as an option.
06:33However, they don't specifically have to be there.
06:36It's one or the other.
06:37If it's both, that's fine too.
06:40So this is a very flexible expression, which is what you're always shooting for.
06:43It accounts for the fact that a comma may or may not be there, and also accounts
06:48for the fact that the decimal point and cents may or may not be there, making it
06:52very useful in multiple situations.
Collapse this transcript
Applying multiple character styles to the same text
00:00In addition to quick and easy formatting, GREP Styles also let you do something
00:04that's otherwise impossible in InDesign, and that is to simultaneously apply
00:08more than one character style to the same bit of text.
00:12The Paragraph Style applied to the body copy in this document already has a GREP
00:16Style built into it that automatically detects prices and formats them by
00:22changing their color and typeface.
00:24What I want to do is change a small portion of that price, just the cents and I
00:29want to apply the superscript attribute through another character style.
00:34I have another character style in this document, called Cents. I'll right-click
00:39on the Cents Style in the Character Styles panel and choose Edit Cents, from the context menu.
00:44In the Character Style Options dialog, let's take a look at what's going on in
00:48this particular character style.
00:49Under Basic Character Formats, nothing about the style is defined uniquely
00:54except that it uses the OpenType Superior/Superscript attribute.
00:59In addition, under Advanced Character Formats, there's a slight Baseline Shift
01:03that positions the numbers exactly where I want.
01:06I'm not making any changes, so I am just going to click Cancel.
01:08Now I am going to go back into the Paragraph Style that's being used here,
01:13which is Body Text, right-click on that, choose Edit Body Text, and go to the GREP Style area.
01:20There are already two GREP Styles built-in here, one for the Figure References
01:24that we saw in a previous movie as well as for the Prices.
01:28What I want to do is take this last portion of the expression, which describes
01:33the cents, which is any two digits.
01:36I am going to copy that to the clipboard using Command+C, or Ctrl+C, and I am
01:41going to create a New GREP Style, and in this To Text field, I am going to paste
01:46in, what I just copied out of the previous style.
01:50And to that I want to apply the style Cents that we just looked at.
01:56If I click off here to see what happens on the page, we instantly have a problem.
02:01I haven't properly defined the cents.
02:03It's taken every pair of digits and applied that Superscript style to it.
02:08What I need to do is require that those two digits be preceded by the
02:13decimal point in the price.
02:15And to do that I am going to use Positive Lookbehind, from the Special
02:19Characters menu, I'll go to Match, Positive Lookbehind, and as my Positive
02:24Lookbehind criteria, which goes in right after the equals sign, I'll type backslash, period,
02:30which defines a literal period, not the any character metacharacter, and I'll
02:34click off here, and that's what I want.
02:37I want to have that Cents style applied only to two digits that follow a period,
02:42and it'll give me that price look that I'm going for.
02:45So here, in this one Paragraph Style, I've got a GREP Style that formats the
02:51entire price with one character style and another GREP Style that formats only a
02:56portion of that price with yet another character style.
03:00This is something you just can't do any other way.
03:02As long as there are no conflicts between the styles I'm using, I can apply
03:07many, many character styles to the same type of text using GREP Styles, and what
03:13do I mean by conflicts? Let's take a look.
03:15Right now, the Cents style doesn't define anything except the superscript
03:21position and that slight baseline shift and that's all it does.
03:24I am going to click OK to commit to this and go back to the Character Styles
03:29panel, and make a change to that Cents Style.
03:32I'll right-click and choose Edit Cents and I'll go to Character Color, which
03:37right now, is undefined.
03:39You see the question mark on the Swatch icons.
03:41I am going to switch that color to Blue, and because Preview is on, you can
03:46see that my cents have now all been colored Blue, overriding the Red in the other GREP Style.
03:53Why did that happen?
03:54Let's take a look. I'll click OK, and go back to the Paragraph Styles panel,
03:59right-click on Body Text to Edit it, go back to GREP Style.
04:03There is a specific order in which styles will be applied and honored in the
04:09GREP Style work area.
04:11The lowest priority is the first item in the list.
04:14Now, if you only have one GREP Style, that's not an issue.
04:17But as you add more GREP Styles, the lower they are in the list, the higher
04:22priority they get and one will override the other, on and on, as you go down the list.
04:27So because Cents is the lowest style in this list, it gets the highest priority
04:32and the Blue attribute that I added to it overrides the red attribute that's
04:37part of the overall price.
04:39If I change the order by selecting the Cents GREP Style here in the list and
04:44clicking the Up Arrow down here, it shifts Cents up one level, and now you'll
04:49notice on the page that the numbers are red again.
04:53Prices now trumps cents and it wipes out the blue attribute.
04:58It doesn't wipe out the superscript attribute, however.
05:01When GREP Styles conflict, it's only the conflicting attributes that gets thrown out.
05:07If another aspect of a character style doesn't conflict, it gets preserved.
05:12So here, the superscript part is preserved, the blue is thrown out.
05:17If I shifted it back down in the list again, with the Down Arrow then that
05:21character style now has a higher priority and the blue overrides the red.
05:26This is how conflicts and priorities are resolved within GREP Styles,
05:30but GREP Styles can also be applied in combination with Nested styles and
05:33Nested line styles.
05:35As long as there are no conflicts among those style attributes, they'll all be
05:39applied simultaneously.
05:41If a conflict occurs, InDesign has a specific pecking order, for which it honors,
05:46and in what order, GREP Styles get the top priority.
05:50Nested Styles are obeyed next, and Nested Line Styles get the lowest priority.
05:55Knowing how InDesign prioritizes style conflicts can help you structure
06:00multiple GREP Styles to apply complex, layered formatting that no other
06:05InDesign feature is capable of.
Collapse this transcript
Describing and styling email addresses
00:00GREP styles excel at matching patterns.
00:03The more you work with GREP, the more patterns you will see and the more you
00:07will want to figure out ways to describe them.
00:09One type of information that follows a very specific pattern and syntax is an e-mail address.
00:15In this movie, we will learn how to write one GREP expression that literally
00:18describes every e-mail address in the world.
00:21One common task most people want to carry out when they are working with e-mail
00:25addresses and text is formatting them in a way that makes them stand out.
00:29And one problem people often encounter is that e-mail addresses can often
00:34break in awkward places.
00:36If there is a hyphen in the addressee name, it can break at the end of a line.
00:41You can see in this example that midway through the e-mail address at the @
00:46symbol, this line breaks and the e-mail address continues on another line.
00:51This never quite looks good and if a hyphen shows up in an e-mail address, even
00:56if Hyphenation is turned off, InDesign considers a typed dash as an acceptable
01:00place to break a line.
01:02And people reading e-mail address may never know, should I type that hyphen,
01:05should I not type that hyphen?
01:07So we want to keep our e-mail addresses together and format them and we want to
01:12do it automatically.
01:13So let's take a look at how to create a GREP style that will identify e-mail
01:17addresses, no matter how different they are, no matter what domain they are, and
01:21automatically style and prevent them from breaking.
01:24My cursor is in this text frame and you can see this Auto style E-mails
01:28paragraph style highlighted in the Paragraph Style panel.
01:31I will right-click that, choose Edit "Auto style E-mails" and in the Paragraph
01:37Style panel, I will go to GREP Style.
01:39Here is where I am going to build my GREP style for formatting this e-mail address.
01:43I will click New GREP Style and from the Apply Style menu, I am going to choose
01:49an existing character style called Non-breaking eMail Addresses.
01:54This applies some formatting changes as well as the no-break attribute, which
01:58keeps the entire e-mail address intact.
02:01Now let's start describing what an e-mail address is like.
02:05I am going to clear out the default and then click off here so we don't have
02:09that formatting on the page.
02:10Let's think for a moment about how e-mail addresses are set up.
02:14There is a certain structure. There is an addressee name, an @ symbol, a domain
02:19name, a period and a domain extension.
02:22That's a specific pattern.
02:24Each part of an e-mail address has specific rules.
02:26Some things are allowed inside of an addressee name, some are allowed inside of
02:31a domain name, some are not.
02:34Domain extensions have a maximum number of letters and a minimum number of
02:38letters in order for them to be valid.
02:40That's how e-mail addresses are parsed out and considered valid.
02:43All of those patterns and conditions and rules that govern an e-mail address
02:49also translate beautifully over to GREP, where you can create character sets and
02:53structure an expression based on those rules to describe an e-mail address.
02:58Let's start with the addressee name.
03:00The addressee name in an e-mail address can only consist of upper or lower case
03:05letters, numbers, the underscore character, a dash or a period. That's it.
03:10Nothing else is allowed.
03:12This is a perfect place for a character set.
03:15From the Special Characters menu, I am going to go down to the Match sub menu
03:20and choose Character Set.
03:21This puts in opening and closing square brackets in which I will build a
03:25character set that describes those acceptable characters.
03:29So I can use any uppercase letter, any lowercase letter or any digit and the
03:34underscore character.
03:35Those are some of what's allowed in here.
03:37And there is one meta character that includes all of those and that's the any
03:41word character meta-character, which is \w. In addition, dashes and periods are
03:47also allowed in the addressee name.
03:49So I am going to go to the beginning of this character set and type my dash,
03:53because that's the best place to include a dash in a character set if you need
03:57to, as we discussed in an earlier movie.
03:59I am just going to type in a period, which is also acceptable.
04:03Since this period is within a character set, it's not the any character
04:08meta-character that's been used throughout this course.
04:11It's a literal period because, when inside of a character set, the period no
04:16longer means any character.
04:18So, any one of those characters is acceptable and there will be many of them.
04:23So, at the end of this character set, outside of the closing bracket, I am going
04:27to type a plus sign, which means one or more times.
04:30So any of the characters within that character set one or more times is
04:34acceptable for the addressee name.
04:36And following the addressee name we need an ampersand.
04:39So I am just going to type that in right here.
04:42Let's just click off now and test this out, see what success we have met with so far.
04:48Not bad.
04:49I am a big fan of testing, especially in GREP styles where you can just click
04:52and look on the page.
04:54So far, we have successfully defined the addressee name followed by the ampersand
04:58and we are not running into any problems with this.
05:00I will go back into this field and let's deal with the domain name.
05:05Domain names are almost identical in the rules they have to follow to addressee names.
05:11In fact, they are just slightly more strict.
05:13But they have so much in common, in fact, that what I am going to do is just copy
05:17the first part of this expression for the addressee name before the @ sign.
05:21Hitting Command+C or Ctrl+C, put my cursor after the ampersand and then paste
05:28that exact part of the expression right after it.
05:31The only thing that's allowed in an addressee name that is not allowed in a
05:36domain name is a period.
05:38So inside of this character set, I am going to delete the period, and now I have
05:42a character set that defines exactly what's acceptable for the domain name.
05:48After the domain name, there is a period that separates it from the domain extension.
05:52Since I am not inside a character set, if I need to describe a period here, I
05:57have to escape it out with backslash, period, so that it describes a literal period and not the
06:03any character meta-character.
06:04I am going to click off again and test my progress so far. Not bad.
06:09I have described the domain names for all of these e-mail addresses.
06:14Let's deal with the domain extensions now.
06:16A domain extension has to be a minimum of two upper or lower case letters and a maximum of four.
06:23So it's even more restricted than anything we have seen so far.
06:27Once again a character set is the best way to deal with this.
06:30I am going to type an opening square bracket to start defining my character set
06:34right here, without going to the menu.
06:36In that, I am going to type \u and \l, for any uppercase character or any
06:43lowercase character, and I am going to end that character set with a
06:46closing right bracket.
06:48That describes what's acceptable in a domain extension.
06:51But I haven't set my limits for how few of those characters and how many of
06:55those characters are allowed.
06:57To do that, I am going to type an opening brace character, the number 2, which
07:02is my minimum acceptable number of characters for a domain extension, a comma,
07:07and then number 4, which is my maximum number, and then end that with a closing brace.
07:13This applies a maximum and minimum range to the entire character set, defined
07:19here, for the domain extension.
07:21So that minimum of two, maximum of four applies to this character set of upper
07:26and lower case characters.
07:28Let's click off and see how we have done.
07:31This is turning out nicely.
07:32I have successfully defined pretty much every e-mail address in this paragraph.
07:38My style has been applied and none of them are breaking.
07:42The only one that I have a problem with is this one down here that has an
07:46optional second domain extension.
07:49This is something that you may encounter and if you want to cover all the
07:52bases and make sure that you write an expression that will deal with any
07:56e-mail address that could show up and prevent you from ever having to manually
08:00apply styles to them,
08:02let's create a condition that allows the possibility for that additional
08:05domain name at the end.
08:07I will go back into this expression and I need to create an optional second domain.
08:13So I want to take a whole ending part of this expression and make it optional.
08:18In order to do that, what I want to do is isolate that last part with a sub expression.
08:23So I am going to start describing this optional second domain within a sub
08:27expression by typing an opening parentheses character.
08:30In there I need to describe a period and any two upper or lowercase characters. So I will type backslash, period,
08:37to describe the period.
08:38I will create another character set with an opening square bracket and in that,
08:43I will type any uppercase letter, any lowercase letter, using \u and \l, just as
08:50I did for the regular domain extension.
08:53After that, I will close off the character set with a closing square bracket.
08:56As you can see I am pushing the limits of this field. It's getting a little bit
09:00harder to see as I type at the end, and then I need to define the range, or the
09:04number of times that this can appear.
09:07In this instance, that's only ever going to be two letters.
09:10That's all that's allowed in that secondary domain extension.
09:13So, I am just going to type an opening brace, the number 2 and a closing brace
09:19and I have imposed a limit of exactly 2 on that character set.
09:23To finish off this sub expression, I am going to type a closing
09:27parenthesis character.
09:28So now I have created a sub expression that refers to the entire second domain
09:34as a small standalone portion of the overall expression.
09:38But since it's optional, and may or may not occur at the end of most e-mail
09:42addresses, I am going to get my cursor at the very end of this field. I am going
09:47to hit the right arrow to make sure I get over there.
09:49You can just see it blinking over there at the edge and I am going to type in a
09:54question mark, which is the zero or one time meta-character, and that applies to
10:00just that sub expression and everything inside of it.
10:03So let's take a look. Perfect!
10:06I have formatted every e-mail in here, I have applied my appropriate style, I
10:11have accounted for secondary domain names, even things like grab up extra
10:15punctuation at the end, like commas and periods that follow domain names,
10:20because the expression has been written to the exact requirements of an e-mail address.
10:25So any pattern that's consistent and follows some rules can easily be described by GREP.
10:32This particular expression will detect any e-mail address, no matter how unique,
10:37no matter if it contains one or two domain extensions and it will format it for
10:42you, make sure it doesn't break, and save you the work of having to do that
10:45manually by yourself.
Collapse this transcript
Dynamically fixing orphaned words with GREP
00:00GREP styles may have been intended to apply visible formatting to text
00:04automatically, but there are some less visible tricks that they can help you perform.
00:09One of my favorites is a GREP style that prevents any paragraph from ending
00:13with just one word on its last line.
00:15A common problem that bugs many editors and designers alike is when a paragraph
00:21ends with one word at the end of a line and a huge space after it.
00:24It just doesn't look good.
00:26In this document, there are a few instances of that problem.
00:30I'm going to go to page 3, and up here at the top, you can see that we have that
00:34problem exhibited here, again on page 5, there is another instance, and on
00:40page 6, another one.
00:43I want to create a GREP expression that detects the last word on any line and
00:48make sure that it doesn't break away from the word that precedes it.
00:52In the past, fixing this usually involved tracking, putting in soft returns and
00:57any number of other less desirable methods that actually end up introducing more
01:02problems down the line as text changes.
01:04So I want this to be a dynamic process, controlled by a GREP style.
01:09I'm going to go back to the first instance of this on page 3, just going to zoom
01:14in a little bit here.
01:15I'm going to hit Command+2, or Ctrl+2 on Windows, to go to 200%.
01:20Let's keep an eye on this part of the page here where the word 'Regime' just
01:25exists at the end of the line by itself.
01:27My cursor is in this body copy, and when I go to the Paragraph Styles panel,
01:32Body Text is highlighted.
01:33I'll right-click on that to edit its attributes and go to GREP Style, and I'm
01:38going to create a new GREP style that's going to help me accomplish this task
01:42and fix this problem.
01:44Since I'm trying to create something that ultimately is never going to be seen
01:49by the naked eye, and can't really be seen on the screen, I'm going to cheat a
01:53little upfront and use a style that's going to make what I do visible, so we can
01:58understand it as I build it.
01:59From the Apply Style menu, I'm going to choose the Yellow Highlight style and
02:04I'm going to start to describe the last word in a paragraph.
02:08Ultimately, what I'm looking for is the space between the last two words, but
02:13we'll get to that in short order.
02:15I'll clear out this Any Digit one or more times default and let's start thinking
02:19about the last word in a paragraph.
02:21The last word in a paragraph would consist of Any Word Character followed by any
02:28punctuation character and then the location, end of paragraph, all of which are
02:33easy to describe with GREP.
02:35Let's start with Any Word Character, which is \w. The word could be many
02:40letters, so let's add a plus sign to that for one or more times.
02:45It's going to be followed by some form of punctuation, and there is actually a
02:48Posix metacharacter that handles any punctuation character.
02:52So I'm going to go to the Special Characters menu, choose Posix and select the
02:57punct metacharacter.
02:59That's placed in here to account for any punctuation mark, question mark,
03:03period, quotation mark. It doesn't matter.
03:06After that, I want to describe its location, which is at the end of a paragraph.
03:11So I'm going to go to Locations and choose End of Paragraph, which puts in the
03:15dollar sign metacharacter.
03:17Let's see if I've successfully defined the last word in a paragraph.
03:21I'll click off here.
03:23Well, I've met with some partial success.
03:25I've identified some words at the end of some paragraphs, but there are a
03:30handful of paragraphs here that have not had the last word highlighted, and
03:34coincidentally, they're all ones that end in quotation marks, because I've only
03:39accounted for one punctuation character after the last word, when there could be one or more.
03:46So let me go back in and add the one or more times metacharacter after the
03:51punctuation Posix metacharacter, by hitting a plus sign. There we go.
03:57I've fixed that problem.
03:59Now, I've found all of the words at the end of these paragraphs.
04:02This is one of the ideal things about testing in GREP, especially something
04:06like this, which I could not see with the naked eye if I wasn't using this Highlight style.
04:11So this describes the last word in the paragraph.
04:14We now want to deal with the space before it and the last character of the word before that.
04:19So I'm going to click back in the To Text field, put my cursor at the beginning
04:23of this expression that describes the last word, and I'm going to type \s to
04:29describe any white space.
04:31I'll click off to see the result. There you go.
04:33It's picked now the last word, the punctuation that follows it, and the
04:36space that precedes it.
04:39Let's now connect it to the last character of the previous word, which would
04:44be any word character.
04:46So I'll type \w at the beginning of the expression, and click off.
04:52These are all the building blocks now, selected and described, that I'm going to
04:56use to pull off this little trick that keeps the last two words together.
05:00The space is what I'm really interested in.
05:02The word that follows it, and the last letter of the word that precedes it are
05:06really just a condition that describes which space I want at what location.
05:12Since they are not something that I want to style, but they are a requirement, I
05:16need to use Positive Lookbehind and Positive Lookahead to describe those as
05:22required, but not something that gets styled.
05:25So, the easiest way to do that, since I have already described this and done all
05:30this work, I'm going to select it and I'm going to copy it to the clipboard
05:35using Command+C. This is the portion of the expression that describes the last
05:39word, the punctuation that follows it, and its location at the end of the paragraph.
05:43I've copied that to the clipboard, and here's what would happen if I selected
05:48this and tried to surround it with the Positive Lookahead syntax.
05:52I'll go the Special Characters menu, and choose Match>Positive Lookahead.
05:58It does not wrap that inside of the expression, which I would really like it to do.
06:03It replaces it.
06:04That's why I copied it to the clipboard.
06:07I'll put my cursor right after that equals sign in the Positive Lookahead portion of the expression.
06:12I'm going to paste that description right back in.
06:14I'm going to click off here, and let's see what we get.
06:19I've narrowed it down.
06:20I still have the character from the word before the space, because I haven't
06:24done anything to that yet, but I've made the last word a required condition
06:28that doesn't get styled.
06:31Now let's do the same thing for the last character in the word before the space.
06:36I'll cut it to the clipboard, make sure my cursor is at the beginning of the
06:40expression, go to the Match submenu and put in Positive Lookbehind.
06:49After the equals sign, I'll paste back in my Any Word Character.
06:53It requires it to be there, but it's not going to style it.
06:56I'll click off, and there you go.
06:59I've identified the space that exists between the last two words in a paragraph.
07:05I don't need the Yellow Highlight style anymore.
07:08All I need is my No Break style.
07:11I'm going to apply that, and click off here and look what it's done.
07:16Adobe's Paragraph Composer has reflowed the paragraph and pulled down the last
07:23word on the line before the last line.
07:26Let's see how well it did it throughout my document.
07:28I'm going to click OK, and I'm going to zoom out a bit.
07:31I'll go to the Pages panel and let's check out the one that was on page 5. That's been fixed.
07:40It was just forester and now it's the forester.
07:44On page 7, instead of just speak, it's to speak.
07:48The lines are still pretty short. There is no way to really control that, but
07:52it's not just one orphaned word at the end.
07:55So the problem has been fixed in all of those places where we saw one word
08:00hanging out by itself.
08:01I just want to point out that, in fact, this has been applied to every paragraph
08:06whether it's a problem or not.
08:08Let me show you what I mean.
08:09I'll zoom in here, and I'm going to select this space between the last two
08:14words in this paragraph, which wasn't a problem, and I'm going to go to the
08:18Character Styles panel.
08:20And you can see, all the way down here at the bottom of the panel, that the No
08:25Break style is identified as existing within this Paragraph Style, even though
08:30it's not really affecting this paragraph at all.
08:33So this fix is actually applied to paragraphs that have no problem with them
08:37whatsoever, like this one, and this one.
08:42But where there is an instance that one word would fall in a line by itself,
08:46it's doing a little bit extra and it's fixing that.
08:49This GREP style, that no one will ever actually see, automatically fixes a common
08:54problem and eliminates the need for other less desirable, and much more
08:58time-consuming fixes.
Collapse this transcript
5. GREP Find/Change
Adding more to the mix: GREP Find/Change
00:00GREP is integrated into two separate features in InDesign CS4, GREP
00:05Find/Change and GREP Styles.
00:07Although each uses GREP to describe text, the two features part company at that
00:12point and work very differently.
00:14GREP styles are built into paragraph styles and they are completely dynamic.
00:19The desired formatting is applied automatically whenever a matching pattern of
00:23text appears in your paragraph.
00:26GREP Find/Change is not dynamic.
00:28You need to run a Find/Change query each time you want to use it.
00:32GREP styles automatically apply character styles, but that's the only
00:36formatting they can apply.
00:38GREP Find/Change can apply both character and paragraph styles, and do so simultaneously.
00:45They can also apply individual formatting attributes that aren't part of a style.
00:49GREP styles can't alter the text they're applied to.
00:53They can't change en dashes to em dashes or add or remove any text, but
00:58GREP Find/Change can.
01:00Text that's found with GREP Find/Change can be rearranged, replaced, remembered,
01:04and referred back to.
01:07There's no real way to save the expressions you write for one GREP style, so
01:11that you can quickly reuse them in another GREP style.
01:14But GREP queries created in Find/Change can be saved and made available from a
01:19menu in the Find/Change dialog.
01:21Not only that, those saved queries are stored as small XML files that you
01:25can distribute over a network or via email, so your colleagues and coworkers can also use them.
01:30So each feature has its own particular strengths and weaknesses.
01:34They both excel at what they do, but how they do it and the circumstances for
01:38choosing one versus the other, are quite different.
Collapse this transcript
Understanding queries
00:00The idea of search and replace is nothing new.
00:03Most of us are familiar with it from applications like Microsoft Word, among others.
00:07But InDesign's Find/Change is a far more robust feature that goes beyond search
00:12and replace and allows you to build and save full queries.
00:16So what exactly is a query?
00:19A query refers to every parameter that's established in the Find/Change dialog.
00:24Everything that's entered in the Find what field and in the Change to field.
00:29Any choices that are turned on or off, like Include Locked layers, Include Locked
00:34Stories, Hidden layers, Master Pages and Footnotes.
00:39Also, any formatting that's been specified as a search criteria and any
00:44formatting that's going to be applied as part of the change operation.
00:48All of that put together makes up a query.
00:52So when you're building a query, that's actually a lot of information if you're
00:55using all of those criteria, and it's the sort of thing that you don't want to
00:59have to do over and over again.
01:01Fortunately, those queries can be saved and reused later.
01:06Anything that you find useful enough to search for once you can do again, without
01:11having to start from scratch.
01:12I am going to build a query and show you what I mean.
01:15In the Find what field, I am going to start a query that cleans up a small
01:19problem in this file.
01:20I've got a lot of double dashes in the text, like here, and down here.
01:27Some of them have spaces around them, some of them don't.
01:30It's inconsistent and I want to use proper em-dashes.
01:34So I want to do a search and replace that cleans up some of this text.
01:38So let's start building this query.
01:40These double dashes may or may not have space around them.
01:43So I want to account for that with the \s metacharacter for any whitespace
01:49followed by the asterisk, which means zero or more times, just in case somebody
01:54typed in two spaces.
01:56I'll type in two dashes, and then another backslash, s, asterisk, for any whitespace, zero or more times.
02:06That's what I am looking for, and I want to change it to an Em Dash.
02:10So I am going to under Hyphens and Dashes to Em Dash and the tilde underscore metacharacter is
02:17put in, which represents an Em Dash.
02:20There's one other thing I want to do and that is to modify the formatting of that Em Dash.
02:26I feel like the Em Dashes in this particular typeface are a little it too wide.
02:30I don't want to go with an En Dash, which is thinner.
02:32So I want to tweak my Em Dash with a character style.
02:36So I am going to click anywhere in this Change Format box, or over here on the
02:40Specify attributes to change icon.
02:43Either one will get me to the Change Format Settings dialog box.
02:47I want to apply a Character Style that actually doesn't exist in this document yet.
02:52So I am going to go down to New Character Style, and I am going to create a
02:56style name called 85% Horizontal Scale.
03:04The only thing I am going to assign to this character style is that 85% value
03:10under Horizontal Scale.
03:11I'll click OK and then OK again, here.
03:17Let's click Find and it finds that.
03:21Now click Change and it applies that.
03:23It's a very useful query.
03:25Now that I have it there, I want to be able to use this anytime I want,
03:29but I want to start from scratch.
03:30So now I am going to save this query by clicking on the Save Query icon up here,
03:36toward the top of the Find/Change dialog.
03:38When I click that, I'm given a dialog to name this query.
03:43I'm going to call it Double Dash to Custom Em Dash.
03:53I won't forget what that means.
03:54I'll click OK, and instantly you can see that it's been added to this list of saved queries.
04:02The list in this menu is broken up into three groups, separated by this thin
04:07horizontal line that you see here.
04:09At the top of the list, above the first horizontal line, are text queries that
04:13have been saved from the Text tab of Find/Change.
04:16Below that, are GREP queries that have been saved.
04:20Below that, at the bottom of this list, are object-based queries for searching
04:24on parameters of what an object looks like.
04:27Each query that you save is automatically saved into the right grouping.
04:30And they are listed in alphabetical order.
04:34If I start working in this document again and I clear out this field and this,
04:39and the formatting here, and I want to recall that search, I simply go up to the
04:44menu, take it from the list, and all the fields are populated.
04:49The only thing that is not saved with a query is the setting that you choose
04:55from this Search menu.
04:57It could be Document, All Documents, Story or To End of Story and if you specified
05:02that when you created the query, it's the only thing out of all the settings
05:06that is not preserved with the query.
05:08So, remember, when you recall a saved query, you always wanted check that you've
05:13established the proper range before you run it.
05:15Not only can you save these queries for your own use later on, you can also
05:20share these queries for other users.
05:23Every query is saved as an XML file in a specific location.
05:28Let's take a look at where it's saved on the Mac.
05:31That's where queries are stored on the Mac OS.
05:34If you're using Windows XP, this is the path where any queries you create are saved.
05:39If you're using Windows Vista and Windows 7, this is the path where all
05:44stored queries get saved.
05:47In fact, someone has sent me a saved query that I want to add to my list, and it
05:51happens to be in the Exercise Files folder.
05:54This XML file is a GREP query that cleans up the formatting of phone numbers.
05:59It's a very useful one that someone is sharing with me.
06:01So I am going to copy this file using Command+C on the Mac, or Ctrl+C on
06:04Windows, and go to this folder where my queries are stored and hit Command+V or Ctrl+V on Windows.
06:11I can immediately go back to the Find/ Change dialog without closing InDesign,
06:16without even closing the dialog box.
06:18When I click on this menu that new query is already there.
06:23I am going to call that query up, and you can see that it's here in the field.
06:27It's a long expression that, fortunately, I don't have the write myself, because
06:31someone provided it for me.
06:32But if I want to modify this expression, let's say I notice that this part of
06:38the expression describes three digits in a row a little bit more efficiently
06:41than this, which is any digit, any digit, any digit.
06:44So I want to modify this expression.
06:46I am going to copy this portion of it, and just clean it up to my liking.
06:52The Query menu has changed to Custom, because I've modified what was a saved query.
06:58If I save this query again, but I don't want a duplicate query, I don't want to
07:02confuse myself, I can pick that existing name and click OK and it asks if I want
07:10to replace the one that was there.
07:11I do, so I'll click Yes.
07:13So now I have my own customized version of this, which I prefer.
07:17While I am here, I want to make this a little bit more useful.
07:20I have got all this setup from the existing query, but if I want the option to
07:26format my phone numbers with dots between the numbers instead of dashes, I can
07:30just type periods in the Change to expression, again I'm now working with a
07:34custom expression different from what was saved before to a different query.
07:38I can click Save Query again, and name this Standardized Phone Numbers-Dot and click OK.
07:50So now I've built upon an existing query, and created a custom version of it for myself.
07:55So I have two possible options for formatting phone numbers instead of just
07:59one, and I can choose them from a list rather than ever having to create them from scratch.
08:04So every setting you define in this dialog box, with the exception of the scope
08:08that you define from the Search menu, can be saved as part of a query.
08:13Considering the potential complexity of many GREP expressions, this is a
08:17great time saver.
Collapse this transcript
Using formatting and styles as Find/Change criteria
00:00By itself GREP is a very powerful feature, but its integration into InDesign
00:05adds even more options that you wouldn't get with GREP in a plain text editor,
00:09specifically, the ability to use nearly all of InDesign's text formatting and
00:14style attributes as additional search and replace criteria.
00:18In this file, I've got a listing of physicians, including a short bio about each one.
00:24I am part way through this project and let's assume there are hundreds of these
00:28in here, and they're all set up, and I'm told that in the headers above the bio
00:33every physician's name must have M.D. appended to the end of it.
00:37This is a very tedious task. I don't want to go in line-by-line and have to do myself.
00:42What I need to do is get that M.D. added to the end of a line only in the
00:47headers, not in the bios or in any other part of this document where I don't want it.
00:52GREP can help me define the end of the line, but only InDesign can help me
00:57define the end of a line that uses a specific style.
01:01Here's how I'd solve this problem.
01:02I'll open the Find/Change dialog, by hitting Command+F, or Ctrl+F on Windows.
01:07Make sure I am in the GREP tab, and also that I'm showing more options, by
01:11clicking the More Options button.
01:13This gives me access to both the Find Format, and Change Format settings, that
01:17are going to be the key to carrying this out.
01:20What I'm looking to do is tack on a comma, a space, and M.D. at the end of each
01:26of these header lines.
01:28To define that, I need to first reference the last character at the end of the line.
01:33That would be any character, and then the end of paragraph metacharacter, so
01:39that's period, dollar sign.
01:42So this describes any character at the end of a paragraph, but whatever that
01:46character is I'm going to need it remembered, and put back.
01:49So I have to enclose it in parentheses to make it a marking subexpression.
01:54As it stands here, I've described any character at the end of any paragraph, not
02:00the specific paragraph I'm looking for.
02:02GREP just can't do that for me. Fortunately, InDesign can.
02:07Since the paragraphs I'm looking for all use the same style, I can limit this
02:11search by its formatting.
02:13To do that, I can either click the Specify attributes to find icon, or just click
02:19anywhere in this box under Find Format.
02:21It opens up the Find Format Settings dialog, and there I'm going to choose the
02:26Doctor's Name Paragraph Style to limit this search to within that style.
02:32I'll click OK, and you can see it appears here Paragraph Style: Doctor's Name.
02:37What I want to replace this with is that last character that I referred to
02:42here, which I'll put back in, no matter how unique it is by using $1, which
02:48means found text 1.
02:50After that I want a comma, a space, and M, period, D, period. Since I'm working in the Change to field I don't
03:00have to worry about escaping out any periods because in the Change to field, a
03:04period just means a period.
03:06It doesn't mean any character.
03:07So I am just going to put my cursor at the beginning of this story, and I am
03:10going to click Change All, and 8 replacements are made.
03:14M.D. has been appended to only the ends of lines that use the style I
03:20specified, Doctor's Name.
03:22But now that I look at it, I want to make a small stylistic change.
03:25The M.D. suffix at the end looks a little bit too big for me.
03:29So I'd like to apply an OpenType feature that's going to reduce in size a little bit.
03:32I am going to clear out the formatting under Find Format, by clicking this Trash
03:37Can icon, because I'm no longer limiting my search to within a specific style.
03:42I am also going to clear out everything in both the Find what and the Change to fields.
03:47This time around what I want to do is single out the M.D. suffix at the end.
03:54So I'll just type M\.D\.
03:59because I'm in the Find what field.
04:01So I need to escape out any periods I type if I am looking for literal periods.
04:05And looking for the M.D. suffix at the end of a line, and I want to apply a
04:10character style just to that.
04:11So I am going to down to Change Format and pick a Character Style called OT All
04:18Small Caps, which applies the all small caps attribute.
04:22I'll click OK and before I click Change All I want to just mention that you'll
04:28notice the Change to field here is empty.
04:30Now, under normal circumstances, an empty Change to field would effectively delete
04:35whatever I searched for.
04:36It would replace it with nothing, but that's not the case when there's a
04:40formatting change involved in the query.
04:43The presence of any type of formatting instruction changes what the Change to
04:48field actually means.
04:49In this instance, an empty Change to field means leave the text as it is.
04:54Only carry out the formatting change.
04:56So I am going to click Change All and 8 replacements are made here.
05:02And I have my slightly smaller suffixes at the end of each doctor's name.
05:06Limiting a query by formatting or style and applying styles as part of a
05:10Find/Change instruction adds an entire InDesign specific layer of functionality
05:15to GREP further expanding its potential and usefulness.
Collapse this transcript
Preserving and recalling using subexpressions
00:00Using subexpressions in the Find what field, you can mark and preserve parts of
00:05an expression that can be referred to and put back as part of the change
00:09operation in a GREP search.
00:11At the end of the Find what field, the Special characters for Search menu has
00:15quite a few options that are GREP specific:
00:17things like Wildcards, Locations, Repeat, Match, and so on.
00:22At the end of the Change to field, it's a much shorter menu.
00:26The only thing here that's really GREP-specific is this Found submenu.
00:31The metacharacters that are inserted from this submenu refer to text that has
00:36been found by the expression in the Find what field.
00:40The first option, Found Text, puts in $0, which refers to everything that was
00:47found in the Find what expression.
00:49The others, which would be Found Text 1 through Found Text 9, refers
00:54specifically to any subexpressions that existed within that expression.
01:00The first subexpression would be Found Text 1, the second, Found Text 2, and
01:05the third, Found Text 3 and so on, and so on, up to 9, at which point InDesign stops counting.
01:11Since this is kind of an abstract idea, I am going to demonstrate it with
01:15an abstract example.
01:17This file has just one text frame in it, and the words first, second, and third.
01:23Each one is a whole word.
01:24So I am going to go to the Find what field, and I am going to start describing the
01:28whole word within a subexpression.
01:31A subexpression is defined by being enclosed in parenthesis.
01:35Anything that exists within that parenthesis is considered a smaller part of
01:39the overall expression.
01:41It can be used just to isolate portions of text, but it can also be used to
01:45count them up and remember them and then request them later on.
01:49So in here I am going to start defining a whole word.
01:51I will put in a word boundary metacharacter, which is \b, the any word
01:57character metacharacter, the one or more times metacharacter, and then another
02:02word boundary character.
02:03So I have described any word character one or more times, as long as it's
02:07surrounded by a word boundary.
02:08That's how I define a whole word.
02:10That definition of a word is enclosed in parentheses, making it a
02:14marking subexpression.
02:17I am going to click Find, and you can see it finds the word 'first', and then find
02:21the word 'second', and finds the word 'third'.
02:24If I wanted to describe each of these one after the other, to make it easier for
02:28myself first I will copy this subexpression by selecting it and hitting
02:31Command+C, or Ctrl+C on Windows.
02:34I need to put a space between each word, and I can just type that in here.
02:38I will paste in what I copied with Command+V, or Ctrl+V on Windows.
02:43Put in another space and paste in another whole word character.
02:48When I click Find, it will find all three words separated by spaces.
02:53But each word, being inside of a subexpression, has been marked off and identified
02:58within the expression, and because they are marked and counted as
03:01subexpressions, I can refer to each of those subexpressions in order.
03:05This one here would be the first one, this would be counted as the second, and
03:10this would be counted as the third.
03:13I can refer back to those using the Found Text metacharacter.
03:17So if I wanted to swap the order, I would go to the Special characters for
03:20Replace menu, to the Found submenu, and instead of choosing Found Text 1, then
03:262, then 3, I could put in Found Text 3.
03:29And I am not going to go back to the menu for each of these, a space, $2, which
03:34is Found Text 2, a space, $1, which is Found Text 1.
03:39So I am asking for the third subexpression, then the second, then the first.
03:44With that defined as my Change to criteria, I am going to click Change, and you
03:48can see that it has put back the third subexpression, the second one, and the
03:53first one, in that order.
03:54I am going to Undo that, and I want to demonstrate a different kind
03:58of subexpression that we haven't seen before, and that is a
04:01non-marking subexpression.
04:03Since InDesign has a limit of a maximum of nine subexpressions that you can
04:07refer to, there may be times when you want to isolate something as a
04:11subexpression, but you don't need it counted, and you are not going to ask for
04:15it back as part of the Change to operation.
04:18I am going to change one of these, the middle one.
04:20I am going to delete it, and go to the Special characters for Replace menu, and
04:24from the Match submenu choose Non-marking Subexpression.
04:29The syntax is slightly different.
04:31It's still enclosed within parentheses, but it starts off with it a
04:34question mark and a colon.
04:35And in there, I can describe the exact same thing:
04:38a word boundary, any word character one or more times, and another word boundary.
04:43But this one, unlike the other two on either side of it, is not going to be counted.
04:48So if I change my Change to expression and ask for Found Text 1, a space, and
04:55Found Text 2, let's see what I get.
04:57I click Find. I have described the whole line, so it's finding it just as it did before.
05:02But when I click Change, I get back first and third, even though there are three
05:08subexpressions, the second one, the middle one, is not counted.
05:12So this one is the first and this one is the second, this one is not counted at all.
05:17That's the difference between marking and non-marking, and the real use for
05:21non-marking subexpressions is to isolate something as a subexpression that
05:25you don't need counted.
05:27If you are writing a very long complex expression, you might actually need to
05:30describe more than nine subexpressions, but you might not need all of them
05:34counted and available to you with the Found text metacharacters.
05:38Since the limit in InDesign is nine references to Found Text, marking
05:42subexpressions can help you out in that regard.
05:45So now we understand this idea in the abstract.
05:48Let's try it with a little bit more concrete example.
05:50I am going to open a file that's in your Exercise Files folder
05:53called nameswap0504.
05:57And here is a practical example of where I might want to rearrange information
06:01very simply, using marking subexpressions.
06:04These names that have been provided in this text are provided, unfortunately, in
06:09last name, first name order.
06:11And that just doesn't look right.
06:13I want to swap them around to first name, last name.
06:16So let's see how we would write that expression.
06:19I will click in the Find what field.
06:20Each one of these starts at the beginning of a paragraph, and it's a word,
06:24followed by a comma, followed by a space, then another word.
06:28Very simple to express in GREP.
06:31The beginning of a paragraph, followed by any word character, one or more times,
06:35followed by a comma, a space, and any other word character, one or more times.
06:42Since I want to move these words around, I need to enclose each of these in
06:46parentheses as marking subexpressions.
06:50And rather than refer to them as Found Text 1 and Found Text 2, I am going to
06:56refer to them as Found Text 2, which is the first name, a space, and Found Text 1.
07:02I don't need the comma and it hasn't been included in my subexpression, so it's
07:06just going to be removed.
07:07Let me click Change All, 8 replacements are made, and I have effectively
07:13swapped those names around.
07:14So just to review, marking subexpressions are counted in the order they
07:18appear, from the beginning of the expression to the end, up to a maximum of
07:22nine subexpressions.
07:24The Found Text metacharacters allow you to recall whatever unique text those
07:28subexpressions found.
07:29Non-marking subexpressions allow you to isolate parts of an expression, but
07:34they are not counted and can't be referred back to using the Found Text metacharacters.
07:39If you find yourself in any situation like this, where you have unique text
07:42that you need to move around and reorder, subexpressions are the ideal way to
07:46do that.
Collapse this transcript
Backreferences in search queries
00:00There's a little-known feature you can take advantage of in GREP Find/Change,
00:04that's not documented anywhere in InDesign's Help files, and that's the ability
00:08to use a back reference to find duplicate information in text and eliminate it.
00:13When text is marked by a subexpression in the Find what field, you can refer to
00:17it in the Change to field with one of the found text metacharacters, like found
00:21text 1 for the first subexpression, found text 2 for the second, and so on.
00:25But you can also refer to those subexpressions within the same expression in
00:30the Find what field.
00:31This is what's called a back reference.
00:34Let's take a look at an example.
00:35In this file, there is a list of addresses and I've noticed that in some of them
00:39some of the information has been entered twice.
00:42I have two address lines for this address here, and here, and another one over here.
00:48So there is at least those and possibly some more.
00:50Now there aren't a whole lot in this document, so I could conceivably go in and
00:54clean them up myself.
00:56But if there are more, then that becomes more tedious work and there's also the
01:00chance that you'll miss something.
01:02By using back references and GREP Find/Change, you eliminate both of
01:06those possibilities.
01:07Let's take a look at how you would refer back to something within the same expression.
01:12The first thing I need to do is think about what I'm looking for.
01:15I'm looking for one line of text followed by another line of text that contains
01:20exactly the same information, a complete duplicate.
01:23So let's start with describing one line of text.
01:27A line of text would be any character, one or more times, followed by a hard return.
01:33I'm going to put that inside of the marking subexpression by enclosing it in parentheses.
01:38So I'll put a parenthesis at the beginning and a parenthesis at the end.
01:42That's describing one line of text.
01:44Technically, it's describing every line of text in this document.
01:48Since it's marked by a subexpression, if I were to refer back to it in the
01:52Change to field, I would use $1 to recall that piece of information.
01:58If I want to refer to it in the Find what field, I can't use $1.
02:03That syntax isn't allowed, in part because the $ is the metacharacter for the
02:08end of a paragraph.
02:10But I can refer to it as \1.
02:14So right after I define a subexpression, I can recall that subexpression.
02:19So what I've just described here is any line of text followed by a hard return
02:24followed by that exact same line of text.
02:27That's how I define a duplicate.
02:29Let's see what that finds for me.
02:31It's found my duplicate addresses here and here and here.
02:35So what I want to replace this with is just the first instance of that line.
02:40Since I've marked the first instance of it as a marking subexpression, I can
02:44just go down to the Change to field and type $1, which means found text 1.
02:49I'm going to click Change All.
02:52Five replacements have been made and five duplicate lines have been
02:56eliminated inside this text.
02:58This undocumented back reference feature is a great way to clean up
03:01duplicate items in any list without having to comb through the text and find
03:05them yourself.
Collapse this transcript
Cleaning up text with GREP
00:00One chore everyone gets stuck with at some point is cleaning up text that's been
00:04provided by someone else.
00:05Often, files come in with two spaces between sentences, multiple returns between
00:10paragraphs, extra spaces at the end of lines, or at the end of the document.
00:14While GREP can't control the quality of your incoming text, it can make
00:17cleaning it up a lot faster.
00:19InDesign ships with a number of saved queries created to handle many of
00:23these cleanup tasks.
00:24Some of them are text-based searches and other are GREP-based searches.
00:28In the Query menu, you'll see a handful of these searches like Dash Dash to
00:31Em-dash, which is a text-based search, and Multiple Space to Single Space,
00:36which is a GREP search.
00:38I'm going to start with the Dash Dash to Em-dash text search, and just point out
00:42some of the limits of doing this with text instead of GREP.
00:46Notice it automatically switches me to the Text tab in the Find/Change dialog
00:50and in the Find what field there are two dashes and in the Change to field there
00:54is the metacharacter for an em-dash which is ^_. I'm going to run this by
01:00clicking Find and then clicking Change , just to do the very first example,
01:04because it immediately points out a limitation of text-based searches.
01:08Although, it has converted those two dashes into an em-dash, there is a space
01:13after that, that I don't want.
01:15As I look at the text in this file, there is a space before these two dashes.
01:18That won't be accounted for either.
01:21There are spaces on either side of this double dash down here. I want all of
01:25that removed. I want to make this as efficient as possible.
01:28I'm going to undo that, and I'm going to go to GREP, because if I were writing
01:32this, I would write it in GREP and I would describe it as Any White Space
01:36which is \s, 0 or more times, which is the asterisk, two dashes, Any White
01:42Space 0 or more times again.
01:45That accounts for the possibility that there may be one or more spaces
01:48surrounding those double dashes.
01:50I want to eliminate those all at once.
01:52What I'm going to change that to is an Em Dash, which I find under Hyphens and
01:58Dashes in the Special Characters for Replace menu.
02:01That puts in ~_, which is the GREP metacharacter for an em-dash.
02:06Let's change all of those. Four replacements have been made. I'll click OK and
02:11not only has it converted my double dashes to em-dashes, it's gotten rid of all
02:16of those unwanted spaces around them.
02:18Since this is a much better and more efficient em-dash search, I'm going to make
02:22sure that I save it from the Save Query menu and I'm going to call it Better
02:27Double Dash to Em Dash, so I know to use that one in the future.
02:32The queries that ship with InDesign, and any custom queries you create, are
02:36great time-savers that you'll probably use on all of your important Word
02:40documents and text files to make short work of common cleanup tasks.
Collapse this transcript
Creating a GREP-based text cleanup script
00:00I love GREP and I am very comfortable with its syntax and structure,
00:03but I have no such expertise or comfort level with writing scripts.
00:07So if I say that it's easy to customize a script that will run multiple
00:11Find/Change queries in a row for you, I mean it. It doesn't require understanding
00:15scripting or writing a script from scratch.
00:17InDesign already ships with a text cleanup script
00:20you can modify to use any custom GREP cleanup queries that you create.
00:24The Query menu at the top of the Find /Change dialog contains many useful
00:28individual queries that you can run to cleanup text.
00:32But you have to run each one, one at a time.
00:35Typically, you're probably going to run several of these, every time
00:38you're cleaning up text.
00:40Ideally, you'd like to run them all one after another, in one shot.
00:44In order to do that, you need to run a script.
00:47From the Window menu, if you don't see Automation in the list, choose Show All
00:52menu Items from the bottom and it will reveal the Automation menu, from which
00:56you'll choose Scripts, which opens up the Script panel.
01:00There's an Application folder, a Samples folder, and then both AppleScript and
01:04JavaScript folders for the scripts that ship and install with InDesign.
01:09The contents of the AppleScript and JavaScript folders are identical, and since
01:14JavaScript is cross-platform, if I'm going to do anything with scripts I'm going
01:17to work with that, in case I want to share the script with someone else.
01:20I'll scroll down the list, until I get to the FindChangeByList.jsx, JavaScript.
01:26That's the script that runs multiple Find/Change queries and that script is
01:31controlled by a text file contained in this Find/Change support folder
01:35called FindChangeList.txt.
01:38Let's take a look at what's going on inside that text file.
01:43This text file is not actually the script itself.
01:46It's a text file that the script calls upon to find out what Find/Change
01:50operations it's supposed to run.
01:52Most of the top of this file is filled with information that's commented out
01:56and provides instructions about what's going on in the file and how you can customize it.
02:01Everything that the script relies upon is down here, at the bottom. All of these
02:06are individual Find/Change queries. Some of them are GREP queries, and some of
02:10them are text queries.
02:12The type of query is identified first, the findWhat criteria is next, the
02:17changeTo is after that, the parameters like including Footnotes, MasterPages,
02:22Hiddenlayers and things like that follows afterwards, and the very last thing
02:26on each line is a description of exactly what that query does, which is quite helpful.
02:31Each piece of this line is separated by a tab, and if you want to customize
02:37this, you can either add a line of your own and start typing it in or you can
02:40modify one of these existing queries, if you have a better method.
02:43For example, down here at the bottom, there's a text query that searches for
02:48double dashes and replaces them with an em dash.
02:51But it doesn't account for the fact that some people type spaces around
02:54their double dashes.
02:56So it won't eliminate those.
02:58GREP can account for the possibility that spaces may or may not exist.
03:01So I'll change text here to GREP and in the findWhat criteria, I'm going to put
03:07in a space just by typing a space because the \s metacharacter is not
03:12recognized within this text file.
03:14So I can only type in an actual space.
03:17So a space zero or more times, before the two dashes, and a space zero or
03:22more times afterward.
03:24I also need to change this text metacharacter that describes an em dash to the
03:29GREP metacharacter that describes an em dash which is ~_. Everything here, under
03:34Footnotes, MasterPages, and so on, I am going to leave exactly the same.
03:38But I am going to modify this description, so I know what this does and I'm
03:42going to add to the end and eliminate spaces.
03:45I'll save this FindChangeList.txt file. I'll go back to InDesign and I'll run this script.
03:52All I have to do is double-click the script name in the list and the script runs.
03:56It's changed everything, including my modified em dash search, and you may have
04:02noticed that there's absolutely no feedback.
04:04You don't get any information about how many matches were found, and you don't
04:09get any option to pick and choose which of the Find/Change queries in that file
04:12get run. They all get run.
04:14So if you are going to add anything to that file, that's going to used by the script,
04:18you want to make sure that that's something you always want to run.
04:21There's no substitute for a pair of eyes on the page to verify that something
04:25unexpected hasn't happened.
Collapse this transcript
6. A Practical Project with Advanced Find/Change and GREP
Describing imported spreadsheet data
00:01InDesign is great at working with Excel files, and turning their data into tables,
00:05but sometimes an Excel file is what you have, but a table is not what you want,
00:10and data received from spreadsheet needs to be rearranged.
00:13Fortunately, there's almost nothing easier to describe with GREP than the
00:17tab-delimited structure of a spreadsheet.
00:20I am going to place an Excel file in this document by going to the File menu,
00:25choosing Place, and selecting embassy_ list.xls from the Exercise Files folder.
00:32I want to make sure when I do this that Show Import Options is on, so that when
00:36I click Open, I get this Microsoft Excel Import Options dialog box.
00:42Here, I want to be sure that the Unformatted Tabbed Text option is what's
00:47selected and not either of these Table options.
00:50I don't want to bring this in as a table.
00:52I am going to click OK, and I get my loaded text cursor and I am going to go
00:56over this existing text-frame on the page and just click to flow the text in.
01:01I will zoom in a little bit here, and then I am going to go under the Type menu
01:06to Show Hidden Characters, so that we can see that this text has come in with tabs
01:13in between each column, or what would have been each column in the spreadsheet.
01:18Every cell in each row is separated by a tab.
01:21This is what's called tab-delimited text and it's what you get when you bring in
01:25an Excel file or copy and paste data out of a spreadsheet into an InDesign
01:29document and you don't do it as a table.
01:31Before I dive into writing my GREP expression, I want to look at what I have
01:35here and think about what I am trying to do.
01:37What am I trying to describe? What's the pattern in this imported spreadsheet?
01:42The original spreadsheet had nine columns.
01:45So, I've got essentially nine cells across each row.
01:50Each cell is separated by a tab, now that it's been imported, and each row is
01:55ended with a paragraph break.
01:58So that's a pretty easy structure.
02:00It's some text, a tab, some text, a tab and so on, until it reaches the last
02:06cell, and there's a hard return.
02:09So let's think about how I would describe this in GREP.
02:12What's inside those cells?
02:14It could be any character.
02:16It could be letters.
02:17It could be numbers.
02:18It could be punctuation.
02:19So the Any Character metacharacter is what I want to go with to describe the
02:23contents of each cell.
02:24There is obviously going to be more than one character, so I should go for the
02:29One Or More Times metacharacter, any character one or more times.
02:33However, if I am thinking ahead, I want to think that it's possible that
02:37there could have been an empty cell somewhere in that Excel spreadsheet
02:40before I imported it.
02:42So I need to account for that as well, as I am describing this.
02:45So instead of any character One Or More Times, I am better off using any
02:50character Zero Or More Times.
02:53This will account for the possibility of an empty cell and still continue down
02:57the line as I write the expression.
02:58So let's start building that.
03:00I am going to open up the Find/Change dialog by hitting Command+F, or Ctrl+F on Windows.
03:05I am in the GREP tab, and I am going to describe the first cell as I have
03:10just though it through.
03:12Any character, which is the period, zero or more times, which is the asterisk and
03:17then it's going to be followed by a tab.
03:20But before I do that, I want to make sure that the contents of the cell is
03:24marked off as a Marking sub-expression.
03:27So, I am going to put my cursor right at the beginning, and put an opening
03:31parenthesis before the period, and a closing parenthesis after the asterisk.
03:36That marks off what I've described as a sub-expression within what's going to be
03:41a much longer expression.
03:43After that, I am looking for a tab.
03:46Each cell should be followed by a tab.
03:48A tab is backslash T, and before I go any further, let me test and see what I get.
03:53I will click Find, and it's a good thing I tested.
03:57I didn't get exactly what I thought it was describing.
04:00Let me move this over.
04:02You can see that GREP, being greedy as it is, has included a tab character as any character.
04:09The Any Character meta character includes tabs.
04:12The only thing it doesn't include is a hard return.
04:14So GREP went as far as it could until it encountered the very last tab, and then it stopped.
04:21So I need to pull this expression back.
04:23I don't want to define all of these cells as you see them selected here.
04:27I want to define them one at a time.
04:29To rein that in, I am going to delete this Zero Or More Times meta character, go
04:34to the Special Characters menu, and from the Repeat submenu, choose Zero or
04:40More Times(Shortest Match).
04:42So that'll only select any character Zero or More Times up until the very first
04:47tab that it encounters.
04:49Let's do one more test and see what we get. Perfect!
04:53It's exactly what I want.
04:54So now I have successfully described one cell, and the tab that follows it.
05:00Across each row, there's a total of nine cells.
05:03So if I want to describe what was a row in the spreadsheet, I need to have this
05:07expression here eight more times.
05:10I am going to select it, copy it to the clipboard using Command+C, or Ctrl+C on
05:14Windows, put my cursor right at the end of it, and paste it in 1, 2, 3, 4, 5, 6, 7, 8 times.
05:23Now, I have a total of nine cells described.
05:26They are all the same, except for the one at the very end.
05:30The last cell in any row is not going to have a tab following it.
05:35It's going to have a paragraph return.
05:38But I don't actually even need to include the paragraph return in this
05:41expression. All I need to do is make sure that that tab is not there.
05:45I am just going to select that, delete it, and let's test this out.
05:49I will click Find, and I am almost there.
05:53The last cell also needs one other difference from all the other cells.
05:58Right now, because I have said Zero or More Times(Shortest Match), it considers
06:03not finding anything in the cell okay, and it stops right there.
06:08So I am going to go back into this expression, all the way at the end, and I am
06:12going to get rid of the Question Mark after the Asterisk.
06:15That changes Zero or More Times (Shortest Match) to just Zero or More Times.
06:21Let's do one more test. Perfect!
06:23That's exactly what I want.
06:25I have described, successfully, a complete row in this spreadsheet.
06:29Let's see how that translates to the other rows.
06:32I will click Find Next. Perfect!
06:34Find Next, Find Next, Find Next.
06:37I am finding them all, as far as I need them to go, stopping at the end of the line.
06:42Once the text in a spreadsheet is described, and each piece of data is marked
06:46off as a subexpression, like I have done here,
06:49you can manipulate, and rearrange that data however you like.
06:53We'll take a look at how to do that in the next movie.
Collapse this transcript
Rearranging imported spreadsheet data
00:01When you've got imported spreadsheet data in an InDesign document, you can use
00:05GREP Find/Change to rearrange that data however you like.
00:09I have got an imported spreadsheet in this file. Now, let's take a look at how to
00:14use an existing query to describe that data.
00:17From the Query menu, I am going to choose the Describe 9-digit Spreadsheet query.
00:23If this doesn't show up in your menu, you can load this query from your Exercise Files.
00:27When I select that, my Find what field is filled with the expression that
00:32describes every row in this spreadsheet.
00:34Each cell is marked off as a subexpression and now I can start moving the
00:39information in each cell around, and changing the structure of this spreadsheet
00:44to something that's more pleasing on the page.
00:47In the Change to field, I am going to start referring back to each subexpression
00:52that was set up in the Find what part of the query.
00:55Each cell is a marked subexpression and there are nine of them across the entire expression.
01:02The first one would be considered Found Text 1, the second one Found Text 2, and
01:07so on and so on until the end.
01:08Now it's up to me to decide how I want this information structured.
01:13There are a few things that I need to overcome.
01:16The first is the order of the information is not quite how I want.
01:21In the spreadsheet it was set up as Last Name First Name, which just doesn't look
01:26as good on the printed page.
01:27So I am going to want to flip those things around.
01:30Each part of my address is broken up into its separate components. The City, the
01:34State, and the Zip are broken out in separate cells, which is great in the
01:38spreadsheet, doesn't look that great on the printed page.
01:41I am going to want to combine those things together.
01:44So I am not going to reassemble this spreadsheet data as it was imported in here.
01:49I am going to start moving it around, combining text that was in separate cells
01:53onto the same line. I am going to add a few things in between, like commas after
01:57the city name and so on.
01:59So let's get started on rearranging this.
02:02First thing I want to do is break up certain parts of information onto separate lines.
02:07The Country name needs to have a paragraph return after it instead of a tab, the
02:12Last Name needs to go after the First Name, instead of the way it's set up now,
02:16and the two need to be on the same line.
02:19Then I need a Return that separates it from the street address, then another
02:24Return that separates it from the City, State and Zip.
02:27And I want to combine the City, State and Zip with a comma after the City and a
02:31space after the state abbreviation and then a Return after the zip code.
02:36After that, I want the Fax number and the Phone number, and before each of those
02:40I actually want to indicate which is which.
02:41So I am going to want to add the text, Phone and Fax between each one.
02:45So there is a lot I am trying to accomplish here and I need to think it through
02:49upfront, so that I can start building the expression that's going to get me that result.
02:53And this is all going to be accomplished with one Find/Change query, in GREP.
02:57I have got nine pieces of information, representing the nine cells in each row
03:03from the imported spreadsheet.
03:05To refer back to those, I need to use the Found meta-characters from the special
03:09characters menu at the end of the Change to field.
03:13The first cell in the imported spreadsheet would be considered Found Text 1
03:17because it's the first subexpression in my Find what search query.
03:21The second cell would be Found 2, third would be Found 3, and so on, all the way up to Found 9.
03:28So I am going to select Found 1 here and then I am just going to actually
03:33type in Found 2 which is $2, Found 3, Found 4, Found 5, Found 6, Found 7,
03:41Found 8, and Found 9.
03:44What I have just described here in the Change to field is essentially all of
03:48the cell data with nothing in between it, not even the tabs, strung together in one shot.
03:54What I am looking to do is actually move some of these things around.
03:57So the second subexpression in my Find what field, which is represented down
04:02here as Found 2, is actually the last name of the ambassador for this country.
04:08The third piece of Found text, Found Text 3 is my third subexpression, which
04:13describes the First Name.
04:15I want to swap these two around.
04:17I want First Name first, and Last Name last.
04:20So I will select $3 for Found Text 3, cut it to the clipboard and then paste it
04:26in before Found Text 2, swapping their order.
04:31Between the two of them, I am going to want to space, First Name space Last Name.
04:37Found Text 1 refers to the Country, and after that I am going to want to hard return.
04:42So with my cursor between Found Text 1 and Found Text 3, I am going to choose
04:47End of Paragraph from the Special Characters menu and it puts in the
04:51meta-character \r. After the First and Last Name, which I've swapped here, I want
04:57another hard return to separate those lines.
04:59So I am going to choose End of Paragraph again.
05:03After that comes the Street address, which is one separate piece of information,
05:08Found Text 4, and it's going to be on its own line so I want to insert a hard
05:12return using End of Paragraph after that too.
05:16Following that, Found Text 5, 6, and 7 refer to the City, State, and Zip.
05:24I want to combine all those onto one line and separate them with the punctuation
05:28of my choice and the space of my choice.
05:30So Found Text 5 describes the City. After that I want a comma and a space. Found
05:37Text 6 is the State. I want a space after that and Found Text 7 is the Zip code
05:43after which I want another End of Paragraph meta-character.
05:47Found Text 8 is the Phone number. Found Text 9 is the Fax.
05:51Before each of these, I actually want to put in Phone and Fax.
05:55So I am going to type in Phone, colon, space
05:58before Found Text 8, put a hard return after it, so it appears on a separate line.
06:03And then before Found Text 9, I will type in Fax, colon, space.
06:08Let's run this query and see what happens.
06:10I will click Change All and 167 replacements have been made.
06:16I will click OK and we'll see what happens on the page. Perfect!
06:20Exactly what I was hoping for.
06:22This first line, which is my header row, is actually giving me the best
06:25indication that I have done this successfully.
06:28Country on one line, First Name, Last Name combined with a space between, Street
06:33on one line, City, comma, space, State, space, Zip, a hard return, the Phone
06:39lead in with a colon and then the phone number and the Fax lead in with a colon
06:43and then the Fax number.
06:44I am going to delete that out of here because I don't need it anymore.
06:49By referring back to marking subexpressions with the Found Text 1 through Found
06:53Text 9 meta-characters, we have been able to rearrange all of this text
06:58replacing tabs with Returns, combining the contents of cells on the same line,
07:03breaking up text onto separate lines and adding pieces of information to the
07:07data that wasn't there before.
07:09And from here on I can just concentrate on formatting, and I have saved
07:13myself 167 manual changes.
Collapse this transcript
Applying styles and formatting with GREP
00:01If you've got a lot of text to format, but it has a similar structure, you can
00:05use GREP Find/Change to apply styles to that text in bulk and save yourself a
00:10lot of repetitive work.
00:11This document contains imported directory listings that all follow a
00:15relatively similar structure.
00:17They start with a country name, an ambassador name, an address, a phone, and a fax number.
00:23Each one contains exactly that information.
00:25There are styles in this document already for each of those pieces of information.
00:29You can see those here in the Paragraph Styles panel.
00:32What I want to do is apply those styles to the appropriate pieces of text in
00:36this document as quickly as possible, and there's no faster way to do that than
00:41with GREP and Find/Change.
00:43Before I start anything like this, I always try to think about what's the best
00:47way to approach this?
00:48Where am I going to run into some problems?
00:50And where's the best place to start?
00:52In this case, the best place to start is with the easiest thing to identify.
00:56There are two things in here that are very easy to describe, and that's the
01:01lines in each listing that start with phone and fax.
01:05Every line starts with that so I can easily identify which lines begin with
01:09phone and apply my Phone style, and which lines begin with fax and apply my Fax style.
01:15I'm in the Find/Change dialog, in the GREP tab, and I want to make sure that I
01:19click the More Options button to reveal the formatting choices available as
01:24part of Find/Change.
01:26Now I'm ready to start describing the different parts of each listing in this
01:30file, and applying formatting to them.
01:32What I'm going to start with is, in the Find what field, I'm to choose a
01:36location, the Beginning of Paragraph followed by the word Phone and a Colon.
01:44I don't want to change that to anything, so I'm going to leave the Change to field blank.
01:48All I want to do is apply formatting to whatever is matched.
01:52To do that, I can click either the Specify Attributes to Change button at the
01:57end of this Change Format Box, or just click anywhere in this box, and the
02:01Change Format Settings dialog opens up.
02:04For every line that begins with the word Phone and a Colon, I want the
02:08Style Phone applied.
02:10I'm going to click OK and I'm going to click Change All, and 166
02:16replacements are made.
02:17I've just applied that style to 166 separate lines of type in one shot.
02:23I'm going to do the same thing for fax.
02:25I left in the Beginning of Paragraph metacharacter and the colon, and just
02:29replace Phone with Fax, and I just need to change my formatting options.
02:34I'll click here in this box and switch the Phone style to the Fax style, and click OK.
02:39Let's do Change All, 166 replacements are made.
02:44It's found the same number and now all of my phone and fax numbers have been
02:49formatted appropriately, including the Nested style built into that.
02:54The next thing I want to deal with is the address.
02:56That's going to be the next easiest part of this to describe, but it's going to
03:00require thinking about how the address is structured.
03:03The address consists of one line with a street address, a Return, and then one
03:09line with city, state, and zip.
03:12More accurately, it's city, space, two letter abbreviation for state, space, and
03:18five digit zip code.
03:20That's a structure that I can define with GREP very easily, and there's a way
03:25to bring the line above it along with me, without having to worry about
03:28describing many, many unique street addresses.
03:32Let's deal with describing just the city, state, and zip first.
03:36I'll clear out the Find what field by hitting Delete.
03:40To describe each city, state, and zip line, let's start with the city.
03:44The city name is some number of characters followed by a comma.
03:48So I'm going to describe any character, one or more times, followed by a comma,
03:54then a space, then any uppercase character exactly 2 times, since that's how the
04:00state abbreviations are structured.
04:03That's followed by a space and then any digit exactly 5 times.
04:09That describes my zip code.
04:11That little concise expression describes all the addresses in this document.
04:16I'm going to just click Find to test this out, and there it is Washington, DC 20008.
04:21Once again, same city, state, and zip.
04:24Here's the New York one, found that just fine.
04:27So I'm confident that this works, and I'm ready to go ahead and continue to
04:31describe this expression.
04:33Both the city, state, zip line, and the address line are going to use the same
04:37paragraph style, my Address paragraph style.
04:40So I want this expression to include the line that precedes city, state, and zip
04:46as well, and that's easy enough to do.
04:48I'm just going to click at the very beginning of the expression, before I start
04:52describing city, state, and zip, and I want to describe one line of text before
04:58that, which is any character, one or more times, followed by a Return. That's it.
05:04Let's take a look at how that works.
05:06I'll click Find to test it out and there you go.
05:09I haven't been specific at all about the street address.
05:13All I've said is there is one line above this pattern of city, state, and zip.
05:18That's all I need to do. So let's run this.
05:21The first thing I need to do is clear out the Change Format settings because I
05:25don't want to apply my Fax Style. I want to apply my Address Paragraph Style.
05:30I'll click OK and I'm going to click Change All and once again, 166 replacements.
05:36Each time I get this result, I feel good because there are 166 records in this directory.
05:42So I'll click OK and there are all my addresses properly formatted with the Address Style.
05:48I'll scroll back up to the beginning here.
05:51The next part of this is a little bit trickier.
05:54I have one line with a country name, and one line with an ambassador name, and I
05:59really can't think of a way to uniquely describe either of these two lines.
06:04An ambassador name could be one or more words. A country name could be one or more words.
06:09There is nothing really unique about these.
06:12So I kind of have to approach this problem from a different angle.
06:15What have I already done so far?
06:18I've applied a number of styles to several parts of each record.
06:22There are just two parts of each record that I haven't applied a style to,
06:26that's the country name and the ambassador name, and each of those is still
06:30using at this point the basic paragraph style.
06:34I'm just going to move Find/Change over here, and you can see in Paragraph
06:37Styles that Basic Paragraph is highlighted because it's still in use by both the
06:42country name and the ambassador name.
06:44So now I don't have to rely exclusively on GREP to help define these two lines.
06:50I can use Styles to help limit my search.
06:52I'll show you what I mean.
06:55I'm going to clear out the Find what field, and I'm going to clear out this
06:59Change Format option by clicking the little Trash Can here and start fresh.
07:03Basically, what I'm looking for are two lines that are still using the
07:07basic paragraph style.
07:09So I want to use formatting as part of my find criteria.
07:13I'll just click in this box and I want to search only text that uses Basic Paragraph.
07:19So I'm limiting my search by a style.
07:22Now I've got two lines that are both using Basic Paragraph, and I don't have
07:26anything unique about the text in them that I can describe with GREP, or do I?
07:31Since it's two lines, what I do know is that I could describe one line, and then
07:36impose a condition on it that it's only a match if there's another line before
07:40it that's also using Basic Paragraph.
07:42So essentially, I'm going to describe the ambassador name line by requiring
07:47another line of text with the same formatting to exist before it.
07:52So this is really approaching the problem from a completely different angle, but
07:55it allows you to accomplish a lot with GREP.
07:57So how would I describe any one line of text?
08:00It would be the beginning of a paragraph, which is the caret metacharacter, and
08:06then any character, one or more times which is Period, Plus and the end of a
08:11paragraph, which is the Dollar sign metacharacter.
08:14That would describe either of these lines.
08:16I'm going to click Find.
08:17Let me move this over, and you can see it selects that country and next, it's
08:22selects that ambassador.
08:23It skips over all of the other information, then goes to the next country and
08:28the next ambassador.
08:29So it's definitely finding only the text within that style.
08:32What I want to do is use Positive Lookbehind, which I'm going to insert at the
08:37beginning of the expression.
08:38I'll go the Special Characters for Search menu, and under the Match submenu,
08:43I'll choose Positive Lookbehind.
08:45I want to require that there is at least one character and a hard return,
08:51which is .\r and that that exists before the line that I've just described.
08:57Let me click Find and see what that does.
08:59It's found the ambassador name.
09:01It's found the next ambassador name, and the next.
09:05I've effectively used Positive Lookbehind to impose a condition that isolates
09:09one of two lines that I have no other real valid way of describing differently.
09:15So, now I can apply my Ambassador Paragraph Style to just the ambassador names.
09:20I'm going to click in the Change Format box, choose my Ambassador Paragraph
09:24Style, click OK and click Change All, and 166 replacements are made.
09:31That's the number I want to see.
09:32Click OK, and I've formatted all of my ambassador names.
09:37Now I can use the same principle, narrowing down my search to text that's still
09:42using the Basic Paragraph style and now it's just the country.
09:45So I can clear out the Find what field altogether because it doesn't really
09:49matter what the text is only that it's still using Basic Paragraph, and I'm
09:53going to leave Change To blank also, and I'm just going to click in the Change
09:57Format box and choose my Country Paragraph Style, and click OK.
10:02Now I'm not even really using GREP at all and I'm not describing what I want to
10:08find or what I want to change.
10:10I'm searching for one type of formatting and replacing it with another type of formatting.
10:15I'll click Change All and 166 replacements are made again.
10:20I'll click OK and there you go.
10:22I've completely formatted 166 records using only a handful of Find/Change
10:27operations, and not doing any of the work manually.
10:31So, you don't have to be specific about every part of an expression or every
10:35part of a Find/Change query.
10:37You just need to define enough to make it unique.
10:40Then you can describe what's around it, and use that as a different type of criteria.
10:45With InDesign styles integrated so well into Find/Change, those become
10:50another tool at your disposal for defining what you're looking for, and
10:54limiting it to something specific.
10:56But whenever you're faced with a GREP challenge like this, the best strategy is
10:59to start with the easy to isolate parts of your text and style them first.
11:04As you keep going, you can essentially make what's left, and what's the most
11:08difficult to define more unique because it will end up being the one thing that
11:12hasn't been styled yet.
Collapse this transcript
Describing and standardizing phone numbers
00:01I'm working in a file of directory listings, and I've noticed a problem.
00:05I have several hundred phone numbers in here and they're not all
00:09styled consistently.
00:10Some of them use dots between the numbers, some have no space at all, some use a
00:141 before the area code, some have that area code enclosed in parentheses.
00:19This could be a very tedious problem for either me or an editor, or it could be
00:24dealt with very quickly and accurately using GREP and Find/Change.
00:30Since I'm dealing with phone numbers, there are some rules that apply.
00:33A US phone number consists of a three- digit area code, a three-digit exchange
00:38and four numbers after that.
00:40That's a structure that all of the phone numbers will definitely have, regardless
00:45of whether they start with 1 or not, use dashes, use periods, do or don't have
00:50spaces, or use parentheses.
00:52So let's start with the structure of a phone number, and how we can define that,
00:57and then deal with the parts that don't match up.
00:59I'm going to open up the Find/Change dialog using Command+F on the Mac, or Ctrl+F
01:03on Windows, and make sure that I'm in the GREP tab.
01:07The first thing I want to do is start to set up the parts of the phone
01:10number that I can rely on.
01:12The consistent part is three digits, another three digits, and then four digits.
01:17So I'm going to type in \d, for the Any Digit metacharacter, and rather than
01:23put in another \d and another \d, I'm going to do that a little more
01:27efficiently by typing an opening brace, the number 3 and a closing brace to
01:31describe exactly three numbers.
01:34To describe the second three numbers, I'll just copy that, paste it at the
01:38end of the expression, and I'm good to go for the first three numbers of the phone number.
01:42I'm going to type Command+V once again and paste that in, but this time I'll
01:46change the 3 to a 4, and now I've described a 10-digit number broken up into
01:52sets of 3, 3, and 4.
01:55I want to make sure that I isolate each part of the phone number with a
01:59marking subexpression, so that it can be remembered by GREP, and recalled
02:03later on, so that I can make a sweeping Find/Change operation, but preserve all
02:08of the unique phone numbers.
02:10So for each of these, I'm going to add an opening parenthesis at the start, and a
02:14closing parenthesis at the end.
02:15I'll just do that again for the second, and then for the last one.
02:21So, I still have my 10-digit number broken up into groups, but now I've marked
02:25those groups with marking subexpressions, and I can ask for them back when I
02:29start changing pieces of the phone number around.
02:31I'm going to click Find and just see what this yields for me.
02:36That's found this one phone number, which exactly matches what I've described, a
02:40string of 10 digits with nothing in between them.
02:44I'll click Find Next, and it identifies the next one that's also formatted
02:47like that, but it's skipping over anything that has spaces, dashes,
02:51parentheses, or starts with 1.
02:53So I need to start adding to this expression to account for all of the possible
02:58ways that someone might have formatted phone numbers for this file.
03:02The first thing I want to account for is the possibility that there might be a 1
03:06before the area code.
03:07So I'm going to go to the beginning of this expression, type the number 1, and a
03:11question mark, which is the metacharacter for 0 or 1 time.
03:16That makes the number 1 optional.
03:17It may or may not be there.
03:19After the 1, there could be a space, there could be a dash, there could be an
03:24opening parentheses, there could be none of those.
03:27So I need to describe a character set of those possibilities and then make it optional.
03:32So I'm going to start a character set with an opening square bracket, and in there, I'm
03:37going to put in all of those characters that I might need: a dash, a period, a
03:42space, which I could either type with the Spacebar or describe using \s for any white space.
03:50There could also be an opening parentheses.
03:53I'll type that in, and then I'll close off this character set with a closing Right Bracket.
03:58I've described what might be there, but it might not be there at all.
04:01So at the end of that, I want to put in the metacharacter for 0 or more times,
04:07which is an asterisk.
04:08With the metacharacter outside the character class, it refers to
04:11everything inside of it.
04:13Let's see what happens when I test that out.
04:15I'm going to click Find and Find Next, and not only am I not having any more
04:21success than I did on the first test, I've actually introduced another problem.
04:25I'm grabbing up the space before the phone number, after the colon, and that's
04:30not something I want to include.
04:32So I need to fix this.
04:33The problem is, since I've made the 1 optional, and then constructed the
04:37expression to say, if you don't find the 1, keep moving on, but a space is acceptable.
04:43It's decided that this space here is fair game.
04:46So I need to limit that a little bit.
04:48I'm going to put my cursor at the beginning of the expression and go to the
04:52Special Characters for Search menu and from the Match submenu, I'm going to
04:56choose Positive Lookbehind, which will require something to appear at the
05:01beginning of this phone number.
05:03In that Positive Lookbehind statement, I'm going to require the presence of
05:07both a colon and a space, which is what follows the lead-in text for both phone and fax.
05:13Let's test this out and see if it's fixed my problem. It has.
05:17I'm still not finding all of the phone numbers I want, but I'm not finding that
05:20space that I don't need.
05:22So let's keep going through the rest of this phone number and describe
05:26what could potentially appear after the area code, but before the actual phone number.
05:31That's right here after this portion of the expression, which describes the area code.
05:35I'll put my cursor in there.
05:38What could appear after the area code is a closing parenthesis that might be
05:42there, a dash might be there, a space might be there, and there is also the
05:46possibility that none of the above will be there.
05:48So I'm going to create a character set that accounts for all of those, just like
05:53I did before the area code.
05:54I'll open it up with an opening square bracket, and I'll put in my matching characters, a
05:59dash, a period, a space and a closing parenthesis this time around.
06:05I'll close that off with a Right Bracket, add the 0 or more times metacharacter
06:10outside of the character set, to define the possibility that they may be there
06:14and they may not be there.
06:15Now I'll move on to the space between the first three digits of the phone number,
06:20represented here, and the last four digits represented here.
06:24I'll put my cursor right between the two marking subexpressions. In between
06:29those parts of the phone number, I'm not going to have to deal with parentheses,
06:33because none of them appear to be formatted like that.
06:35So there might be a space, there might be a period, there might be a dash.
06:40I'll create another character set, and in there I'll put a dash, a period, a
06:45space, close off the character set and use the 0 or more times, Repeat
06:50metacharacter after that.
06:52That should describe every possible way that someone has typed in a phone number here.
06:58Let's see if it works.
06:59I'll click Find, and that's better. I've found phone numbers with dots
07:04between the numbers.
07:05Phone numbers with dashes, dots again, phone numbers with a 1, a dash, a
07:11parentheses and so on.
07:13I'm feeling confident that I've written the expression that's going to
07:15accomplish what I want.
07:16So we've dealt with the first half. We've described a phone number in all of its
07:22possible formatting options.
07:25Now what we want to do is strip away all that inconsistent formatting and
07:29rebuild all these phone numbers with one format.
07:33What I want is the area code with nothing before it, and no parentheses around
07:37it, a dash, the first three numbers, a dash, and the last four, very simple, old
07:43school phone number formatting.
07:45So, how do I describe this?
07:47I need to call back those portions of the phone number that I want to keep.
07:51I certainly want to keep the area code and all the digits of the phone number.
07:56Since I've marked them with marking subexpressions, I can pull back each unique
08:00one, because they'll be remembered as the Find/Change operation progresses.
08:04To recall any text that was found in the expression, I'll go to the Special
08:08Characters for Replace menu, to the Found submenu and pick Found Text 1.
08:14That describes my first subexpression, which is the area code.
08:18I want to add a dash after that.
08:21Then I want to recall my second subexpression, Found Text 2, which is $2.
08:27I want to have a dash after that.
08:28Then I want to specify my third piece of Found Text, which is Found Text 3,
08:34very simple, concise expression that strips away all of the parts of these
08:38phone numbers I don't want, and puts the phone numbers back together with
08:42formatting that I do want.
08:45Let's click Find Next to test this out.
08:48I'm going to change just 1, because it's always good to try 1 before you commit,
08:54and that works just fine.
08:55It keeps my phone number and puts my formatting around it.
08:58I'm going throw a caution to the wind, and click Change All.
09:01332 replacements have been made.
09:05Let's click OK to see it reflected on the page.
09:08There you are.
09:09Hundreds of phone numbers, described regardless of how inconsistent they
09:13maybe, remembered, reassembled and formatted exactly as I want, with 1
09:18Find/Change operation.
Collapse this transcript
Inserting anchored objects with GREP
00:00Although GREP is primarily a text- based feature, you can actually use GREP to
00:05insert graphics too.
00:07By combining GREP Find/Change, Styles and Anchored objects, we're going to see
00:12how you can insert hundreds of anchored object frames in mere seconds.
00:16To finish off the layout of this directory of embassies, I want to add before
00:21each country name, a small graphic frame into which artwork for the flag of that
00:25country is going to be placed.
00:27They are going to go in as anchored objects, so that they flow with the
00:31text and they all appear in the same place above each line.
00:34So the first thing I'm going to do is create a graphic frame for myself as a
00:38placeholder to receive those files when I'm ready to place them.
00:41I will draw a frame out here with the Frame tool, roughly the size and
00:45dimensions of a small flag.
00:47I'll switch to the Selection tool and then from the Edit men, choose Cut to copy
00:53it to the Clipboard.
00:54I'm going to put my cursor in at the beginning of the very first letter in the
01:00very first country in this list and then I'll go to Edit>Paste to insert that
01:05object and by default, it goes in as an inline anchored object.
01:09I will switch back to the Direct Selection tool, click on the Graphic frame and
01:15then right-click and go to Anchored Object>Options.
01:19By default, this is an Inline object that sits to the left of the text.
01:23I actually want to make it an Above Line object so that it sits above that line
01:28and I want to add a little space after it, so I am just going to notch that up
01:32in the Space After field and that's about what I want.
01:34I will click OK and now that I've got this positioned and anchored exactly the
01:40way I want, I want to save all of those settings as an Object Style.
01:45From the Window menu, I'll choose Objects Styles and I'm going to create a New
01:52Object Style by choosing that option from the panel menu.
01:56I'll name this object style 'Anchored Flags' and then I'll go over the Anchored
02:02Object Options for this style and we can see that what I just did, has been
02:05picked up and built into the style automatically.
02:08I'm going to add one more feature in here.
02:10I'm going to activate Frame Fitting Options.
02:13I want to make sure that whatever graphics get placed in these frames, when I am
02:17ready to take that step, will fit proportionally in that frame, so I will choose
02:22Fit Content Proportionally.
02:25That's going to resize the graphics as they are placed.
02:29One last thing I want to do though is go to General and make sure that Apply
02:33Style to Selection is on, so that when I click OK, you can see that the selected
02:40object, which I already pasted, has Anchored Flags applied to it automatically.
02:45I'll close Object Styles because I am done with that and then I'll select this
02:49frame again and I'm going to cut it to the Clipboard.
02:54Now that that frame is in the Clipboard, I'm going to start inserting it
02:58everywhere that I need it using Find/Change and GREP.
03:01I will hit Command+F, or Ctrl+F, on Windows to open the Find/Change dialog.
03:07I'm in the GREP tab, but I want to make sure that I click More Options because
03:11I'm going to want to describe formatting as a search criteria to make this work.
03:17Before I start entering anything in the Find what field, let me think about
03:20exactly what I'm trying to do.
03:22I have something in my Clipboard.
03:24I want to insert that object that's copied to the Clipboard at the beginning of
03:29every line that's using the Country Paragraph Style.
03:33I know that I need to describe a location at the beginning of a paragraph, which
03:37I can do with the caret metacharacter.
03:40Because a location can't actually be changed, this isn't enough for me to carry
03:45out what I need to do.
03:46I also need to describe the first letter at the beginning of that paragraph.
03:51But I'm going to need to remember what that letter is and ask for it back again
03:55when I'm ready to make my changes.
03:57So I'm going start a Marking Subexpression with an opening parenthesis and put
04:02the any character meta character in it and close off the Subexpression with a
04:07closing parentheses.
04:09So I'm asking for one single character that exists at the beginning of a
04:14paragraph but not any paragraph, only paragraphs that use the Country
04:19Paragraph Style.
04:20So I need to go down and specify formatting attributes to find.
04:25Click this icon here and I'm going to select my Country Paragraph Style
04:31and click OK.
04:32Now I've defined any character at the beginning of a line using the
04:36Country Paragraph Style.
04:38So, I'm ready to start writing my Change Expression.
04:41What I'm trying to insert is a Graphic Frame.
04:44I've copied it to the Clipboard, but I can't just paste it into the Change
04:47to field.
04:48It doesn't work that way.
04:50However, there is a little known meta character in both Text Find/Change and
04:54GREP Find/Change that I can use to accomplish the same thing.
04:58From the Special characters for replace menu, I'll go to the Other submenu and
05:04I'm going to choose Clipboard Contents, Formatted.
05:08This is the only way, in InDesign, where you can actually use Text-based
05:12Find/Change to put in anything you want.
05:15It could be a Graphic Frame, like I'm trying to do.
05:18It could be a Stroke.
05:19It could be another Text Frame.
05:21It could be anything that's copied to the Clipboard.
05:23So I will choose Clipboard Contents, Formatted.
05:26It puts in the tilde C meta-character.
05:29But I also want to recall the first letter that I defined up here in that
05:34paragraph and put it back.
05:37So after the Clipboard contents metacharacter, I'll go to the Special characters
05:41menu to Found and choose Found Text 1, the first Subexpression in here, the
05:48first bit of Found Text.
05:50I'm asking for that back and it's going to be put back in, preceded by this
05:54anchored Text Frame.
05:55Let's try a test, and I'm going to do the first one.
05:58So it's found what I've described, any character at the beginning of a paragraph
06:02that's using the Country Paragraph style.
06:05I am going to click Change and let's see what we get.
06:09It's inserted my object above that line and replaced that first character
06:14that it's found.
06:16Let's click Find Next just to be sure.
06:19It's finding what I want. I'll click Change and it's changing what I want.
06:24So I'm confident that I have structured this Find/Change operation to do exactly
06:28what I want, consistently, through the document. Just to make sure I don't
06:32accidentally repeat inserting those in the two instances where I've already put
06:36it in, I'm going to click into the text in the frame on the page.
06:40And then I'm going to go back to Find /Change and change my search criteria
06:44to To End of Story.
06:47And now, I'm going click Change All and InDesign will process this for a moment,
06:53and it's processed to 164.
06:56Let's click OK and there you can see them on the page.
06:59Let me zoom out and go to page 1 in this document and there's 166 anchored Text
07:07Frames placed in a precise location through out a multi-page document using one
07:13Find/Change operation.
07:15So, now I've got 166 placeholder frames exactly where I want them, ready to
07:19start to receive graphics.
07:21I'm going close the Find/Change dialog because I've gone as far as I can go in
07:25this process using Find/Change and GREP.
07:28But let's just take a look at how you would finish this off, starting with
07:31say, the first 10 flags.
07:34I'll choose File>Place and from the Links folder, I'll select the first piece of
07:40flag art in the list by clicking its name and Shift+Clicking on the last name in
07:45the list to select all 10.
07:48I'm going to turn-off Show Import options because I want to see 10 successive
07:52Show Import options dialogs when I do this.
07:55Now I'll click Open and I get InDesign's loaded multi-file place gun and a
08:01preview of the first of the 10 images that I'm ready to place.
08:06I can just hover over one of the frames that I placed using GREP earlier, click
08:11in that, and it automatically places the art and sizes it to the frame.
08:15I'll go ahead and click the next one and the next one and the next one, so
08:20on and so on.
08:21And this is exactly how I would go about finishing off this project if I was
08:25going to take it to conclusion and do all 166 countries.
08:28So let's just review what we've done here.
08:31We've used GREP Find/Change to identify a specific location within text that
08:38uses a specific paragraph style.
08:40We've also used it to insert objects pasted to the Clipboard as anchored
08:45objects within that text.
08:48After that, that's as far as we could go with Find/Change, but we were able to
08:51take advantage of other InDesign features to drop in multiple images
08:56throughout a project.
Collapse this transcript
Conclusion
Goodbye
00:00So you've made it all the way through. Congratulations!
00:03We've covered a lot of very technical territory in these past few hours and
00:06I hope you've come away with not just examples of what GREP can help you
00:10accomplish, but a real understanding of GREP, metacharacters, Find/Change, and GREP styles.
00:16If you've been reluctant to try GREP on your own, I hope you're ready now to
00:20dive in and start taking advantage of one of InDesign's most powerful features.
00:24I am Michael Murphy.
00:25Thanks for watching!
Collapse this transcript


Suggested courses to watch next:

InDesign Secrets (8h 57m)
Anne-Marie Concepcion


InDesign CS4 Beyond the Basics (8h 3m)
David Blatner

Using Regular Expressions (5h 36m)
Kevin Skoglund


Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 98,468 instructional videos.

start free trial learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 1,894 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.


site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked