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