Global grep difficulties Power Headers Forum

Avatar

Please consider registering
guest

sp_LogInOut Log In

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 4 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Global grep difficulties
06/03/2011
11:27 am
Avatar
Dave Peattie
Member
Members
Forum Posts: 6
Member Since:
05/04/2011
sp_UserOfflineSmall Offline

I've been trying to get a complicated header going with various sublevels and I'm trying to get rid of repeated elements.

 

note <-> = en dash

First Head 1 (First Head 2) <-> Last Head 1 (Last Head 2)

For when the First Head 1 and the Last Head 1 are the same, I'm trying to create a global GREP to make it look like this:

First Head 1 (First Head 2 <-> Last Head 2)

But it doesn't seem to work.

 

Here's what I did:

GREP search for:

(.+)\((.+)~= \1 |(

 

replace with

$1($2~=

 

But that didn't work.

06/03/2011
11:42 am
Avatar
Harbs
Admin
Forum Posts: 201
Member Since:
12/19/2010
sp_UserOfflineSmall Offline

I just responded to you privately.

 

I'll write up a full explanation next week when I have a bit more time...

 

Good luck!

Harbs

06/05/2011
6:18 pm
Avatar
Harbs
Admin
Forum Posts: 201
Member Since:
12/19/2010
sp_UserOfflineSmall Offline

Dave's document was an awesome example to illustrate the power of Power Headers. Thanks Dave, for letting me share this!

I'm going to try to explain Dave's issue as well as the solution:

 

Dave was working on a rather complex technical publication. The text is an examination of many different plant life and there were families further broken down into genera. The header were required to reflect the current family and genus range. Like this: Family1 (Genus1) – Family2 (Genus2). This situation was further complicated by the fact that not every page has multiple families or genera. The Genus listed had to be a sub-category of the family listed as well.

Here's some examples of how it could look:

1. Family1 (Genus1) – Family2 (Genus2)

2. Family1 (Genus1) – Family2

3. Family1 (Genus1)

4. Family1 (Genus1 – Genus2)

 

Here's how Power Headers solved his header problems:

1) Basic setup: Dave created 4 headers to deal with these 4 variables. Let's call them Family1, Genus1, Family2, and Genus2, and he used a static space, endash between header 2 and 3. Headers 1 and 2 were set up as "Current Instance" which picks up the current section from the previous page if need be. Header 3 and 4 were set up as last instance. So far so good.

The issue with case #2 is that when the new family starts near the bottom of the page, there's no Genus text to pick up which is within the new family. In this case, the genus text must be dropped, but we need a way for Power Headers to know this! Power Headers has a solution built in which we call "Resetter Styles". Basically, you can "reset" your header any time a specific style is encountered. In this situation, Dave needed to tell Power Headers "loose your memory of the Genus text any time you encounter Family text. Here's a screenshot of the setup which does that:

Resetter StyleImage Enlarger

 

The important selection is outlined by the red box. Only instances of Genus which appear after all instances of the Family style will be used.

 

Situation #3 and #4 are even more complex because very often the Genus appears on the page, therefore there is a last instance. The Family has this problem less often, but it can have this issue as well. In situation #3, the second instance of the Genus needs to be stripped out, and sometimes the secind instance of the Family as well. In situation #4, the (same) Family must be stripped out between the two genera.

 

This seems like an almost impossible situation. In fact I had some trouble working it out myself… Wink

 

Power Headers has a feature called GREP Processors which can be defined within a header variable which allows dynamic replacement of text while the header is being built.

 

It also has a feature called Global GREP Processors. The differenc between the two, is that Global GREP Processors work on the entire header frame while the variable ones only work on the text of a specific variable. In this situation, we needed a Global GREP Processor because the different variables needed to interact with each other.

 

Here's the idea behind how it works:

Most people know that you can use groups and refer to different groups of a GREP find in the replace field (i.e. using $1, $2, etc.).

What most people don't know, is that you can refer to the groups in the find field too. This is a standard regular expression feature supported by most engines, and InDesign supports this as well (although to the best of my knowledge it's not documented). The syntax for group matching with the find is a bit different than the syntax in the change field. In the change field you use a dollar sign and a number, but in the find field you need to use a backslash and a number so when you'd use $1 in change, you need 1 in find.

 

So basically, we need to find the header element which repeats itself and we use a regex group for that.

Here's a couple of the necessary Global GREP Processors needed in Dave's case:

This finds repeating genera and strips out the second one:

Find: (w+) ~= 1

Replace: $1

 

This finds repeating families and brings the two genera together:

 

(w+)( (w+)) ~= 1 ((w+)

change to: $1$2 ~= $3

 

I hope some other people find this example as useful as I think it is! :-)

 

Harbs

06/15/2013
12:12 pm
Avatar
Dave Peattie
Member
Members
Forum Posts: 6
Member Since:
05/04/2011
sp_UserOfflineSmall Offline

Hi Harbs. 

 

I'm back to a (not nearly as) complicated science book and revisited the post to do a similar global GREP processor setup. However, I think that in your sample above, you refer to the backslash before certain "find" variables, but they don't seem to be listed above, or at least my browser isnt' showing them.

I changed to:

(\w+) ~= \1

Replace: $1

But now I've got a bit of a problem. I discovered that if the last letter of the first instance of a word before the en dash is the same as the first letter of the word following the en dash, the letter, the en dash, and the repeated letter will be deleted.

So

Text – Test

Becomes

Texest

I thought perhaps the backslashes were the problem, but the GREP didn't work at all without them.

06/16/2013
12:47 am
Avatar
Harbs
Admin
Forum Posts: 201
Member Since:
12/19/2010
sp_UserOfflineSmall Offline

You probably want to limit the GREP to more than a single character. Something like this should do the trick:

(w{2,}) ~= 1

You'll want to change the 2 to the minimum number of characters you'll have to avoid false positives.

 

Actually, a better way of doing this would be to specify a word boundary like this:

(bw+) ~= 1

See here for more details:

http://www.regular-expressions.....aries.html

06/17/2013
1:27 pm
Avatar
Dave Peattie
Member
Members
Forum Posts: 6
Member Since:
05/04/2011
sp_UserOfflineSmall Offline

Thanks Harbs. And thanks for the link to Reg-Ex! Very helpful.

 

Dave

Forum Timezone: America/New_York

Most Users Ever Online: 197

Currently Online:
1 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

jacksonlame: 18

niftyix: 10

Ulrich Bogun: 9

jackferthomas: 8

Adrian: 8

Soyablack123: 7

Member Stats:

Guest Posters: 1

Members: 6009

Moderators: 0

Admins: 2

Forum Stats:

Groups: 3

Forums: 23

Topics: 279

Posts: 705

Newest Members: MWillustration, Our Daily Bread Ministries, ncbydkABItsYOXM, YdNescPZ, alexnew, qEJlnQXkCF

Administrators: In-Tools: 11, Harbs: 201