GREP recipes wanted: find first word/phrase and date range analysis

532 views
Skip to first unread message

XMLpro

unread,
Dec 12, 2010, 8:45:41 PM12/12/10
to InDesign talk
I need to find the first word or set of words of a paragraph when it
is set off by a comma and space after it, followed by another word
starting with a capital letter, i.e.
Abbott, Marie-Anne
Van der Rhyn, Willem
I want to apply a character style to "Abbott" and "Van de Rhyn", not
including the following comma. I would like the definition for space
after the comma to include non-breaking, thin and normal spaces.
What is the InDesign GREP pattern that can help me locate this
situation? These occur now in a list of people and their descriptions,
from which I need to locate just the last names, which start each
sentence.

I also need to locate date ranges, which may be 300-250, 300-350,
5-122, 1871-1934, etc. So the pattern is one or more digits separated
by a hyphen followed by one or more digits. I would like to know if
there is a way to identify the BCE dates by the fact that the value of
the first number part is greater than that of the second number (such
as 300-250). Then I could apply character styles for CE and BCE dates
differently.

Then I wonder, should we start collecting such recipes somewhere, and
if so, where -- or is there such a resource of specific solutions that
I don't know about? I'm interested not in general GREP, but in
InDesign GREP recipes that take into about the special markers, etc.
as well as text patterns generally.

Roy McCoy

unread,
Dec 13, 2010, 3:56:51 AM12/13/10
to indesi...@googlegroups.com
You should read this:

http://oreilly.com/catalog/9780596156015

I'd say collect your own patterns.


Roy

Michel Raj

unread,
Dec 13, 2010, 3:59:07 AM12/13/10
to indesi...@googlegroups.com
And it's worth every cent !

Michel

> --
> you are subscribed to "InDesign talk" on Google Groups, to post: send email to indesi...@googlegroups.com, to unsubscribe: send email to indesign-tal...@googlegroups.com, for more options visit http://groups.google.com/group/indesign-talk

Roy McCoy

unread,
Dec 13, 2010, 4:15:49 AM12/13/10
to indesi...@googlegroups.com
Michel Raj wrote:

And it's worth every cent !

Yeah. One thing that's helped me with developing a collection of patterns, by the way, is always naming them with prefixes that keep them grouped and thus more easily refindable in the Find/Change window list. For example, the first two I see: "Tabs - Multiple to Single" and "Tabs - Strip Leading Single". Also by job for repeating-job patterns: "JL - Find Multiple E-mail Addresses", "JL - Fix Line-Divided Phone Numbers", etc. (JL being Jarlibro, yearbook).


Roy

XMLpro

unread,
Dec 13, 2010, 1:34:18 PM12/13/10
to InDesign talk
Hi, I recommended Peter's GREP in InDesign book in another posting to
this forum. When you're just starting out with GREP, the syntax is
confusing (at least it is to me) and I was hoping someone would help
by writing some part of the expression so I could look at theirs to
see what I was doing wrong. I personally have a hard time getting
InDesign to accept GREP expressions that I have composed by typing,
even when using the menus to select bits of the expression. I'm sure
I'll get better with practice, and may get the expression composing
app that several people have recommended, RegexBuddy's Regex Builder.

C F Majors

unread,
Dec 13, 2010, 2:26:51 PM12/13/10
to indesi...@googlegroups.com
I have just been to OReilly and got me some stuff. This is a good day
to do it. They have some shortcut books for 3.99 today only.

Thanks for getting me to Peter's book. Thanks Peter for writing it.

Also a fan of Blatner, Kvern, Concepcion and McCue. Anyone else I
should add to my list? I am trying to stimulate the economy with
knowledge from my favorite writers this year. Using magic-card money,
of course. I'm up-to-date with you plug-ins people, I think.

8-)

Carol

> --
> you are subscribed to "InDesign talk" on Google Groups, to post: send email to indesi...@googlegroups.com, to unsubscribe: send email to indesign-tal...@googlegroups.com, for more options visit http://groups.google.com/group/indesign-talk
>

--
Carol Majors / Publications unltd
Raleigh NC
.   .   .   .   .   .   .   .   .   .   .   .

Roy McCoy

unread,
Dec 13, 2010, 2:13:27 PM12/13/10
to indesi...@googlegroups.com
On Dec 13, 2010, at 7:34 PM, XMLpro wrote:

> When you're just starting out with GREP, the syntax is confusing

> (at least it is to me) [...] I personally have a hard time getting


> InDesign to accept GREP expressions that I have composed by typing,
> even when using the menus to select bits of the expression. I'm sure
> I'll get better with practice,

Everybody else does, so there's no reason you shouldn't either.
The patterns you wanted seemed very basic and simple, so there was
likely a feeling here that you could figure them out yourself and
probably should. To apply the character style you wanted, for example,
change

^([^,]+),

to

$1,

with the style set in Change Format.

> I also need to locate date ranges, which may be 300-250, 300-350,
> 5-122, 1871-1934, etc. So the pattern is one or more digits separated
> by a hyphen followed by one or more digits.

Again simple:

(\d+)-(\d+)

to

$1-$2

> I would like to know if
> there is a way to identify the BCE dates by the fact that the value of
> the first number part is greater than that of the second number (such
> as 300-250).

A script could presumably be worked out to do that, but it would be more trouble than it was worth for any normal print job.


Roy

Amy Rothstein

unread,
Dec 13, 2010, 2:31:10 PM12/13/10
to indesi...@googlegroups.com
While you're doing this, can you change them to proper N dashes instead of hyphens?


On Dec 13, 2010, at 2:13 PM, Roy McCoy wrote:

>> So the pattern is one or more digits separated
>> by a hyphen followed by one or more digits.


----------------------------------
Amy Rothstein
a...@pondproductions.com
----------------------------------

Roy McCoy

unread,
Dec 13, 2010, 3:03:43 PM12/13/10
to indesi...@googlegroups.com
Yes, just put en dashes in place of the hyphens.

Roy

Peter Kahrel

unread,
Dec 14, 2010, 7:35:31 AM12/14/10
to InDesign talk
This expression:

^\u\w+(?=, \u)

Matches your names. Details:

^ start of paragraph
\u upper-case letter
\w one or more word characters (letter, digit, space)
(?=, \u) is a lookahead, in this case it paraphrases as "if followed
by comma space capital.

In the Change Format panel, enter the character style you want to
apply.

Numbers:
Find what: (?<=\d)-(?=\d)
Change to: ~=

Details:
(?<=\d) is a lookbehind, here paraphrases as "if - is preceded by a
digit (\d)"
(?=\d) is again a lookahead: "if - is followed by a digit".
The whole expression therefore reads "if a hyphen is preceded and
followed by digits".

As to finding BCE dates, as Roy mentioned, you need a script for that.

Peter

XMLpro

unread,
Dec 14, 2010, 2:45:55 PM12/14/10
to InDesign talk
Wonderful explanation and thanks so much for that pair of expressions,
Peter.

XMLpro

unread,
Dec 14, 2010, 3:07:52 PM12/14/10
to InDesign talk
Reply all
Reply to author
Forward
0 new messages