• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Grep - How to find non-italics characters followed by italics

New Here ,
Feb 28, 2017 Feb 28, 2017

Copy link to clipboard

Copied

Hello everyone...

Is there a way to grep all non-italics characters followed by an italics punctuatiob, e.g., serach for "Review of Religions," in this word, the punctuation "," is not italics, I would like to serach of all types of punctuation that are not italics, and change them to italics, same would be the case for bold, and bold-italics.

Another way looking at it would be a grep that could search for any italics character followed by a regular punctuation, and a bold character follwed by a non-bold punctuation, and a bold-italics character followed by a non-bold-italics character.

Thanks in advance!

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

I would run this 3 times:

Find What: (\,|\;|\:)

Find Format: Regular

Change To: leave blank

Change Format: Character Style Italic

The second time you run it I would reset to Bold Character Style.

The third time I would run it I would reset to Bold Italic Character Style.

Automatic? No. But it would allow you to inspect each occurrence, and it would only take 5 minutes.

Mike Witherell

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

Look for grep manager script or the multi find and change from automatication. The first is free. Once you have the query you can load them in a set and ececute them all in one click.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2017 Mar 02, 2017

Copy link to clipboard

Copied

Hi,

Just this:

app.findGrepPreferences = null;

app.findGrepPreferences.findWhat = ".[.,;:!?…]";

myFound = app.activeDocument.findGrep();

var F = myFound.length;

for (var f = 0; f < F; f++) {

    var myCharStyle = myFound.characters[0].appliedCharacterStyle;

    if (myFound.characters[-1].appliedCharacterStyle !== myCharStyle) myFound.characters[-1].appliedCharacterStyle = myCharStyle;

    }

app.findGrepPreferences = null;

Of course, if you only want to catch "Italic", "Bold" and "Bold Italic" and avoid to catch, say, URL, you could play this:

app.findGrepPreferences = null;

app.findGrepPreferences.findWhat = ".[.,;:!?…]";

myFound = app.activeDocument.findGrep();

var F = myFound.length;

for (var f = 0; f < F; f++) {

    var myCharStyle = myFound.characters[0].appliedCharacterStyle;

    if ((myCharStyle.name == "Italic" || myCharStyle.name == "Bold" || myCharStyle.name == "Bold Italic") && myFound.characters[-1].appliedCharacterStyle !== myCharStyle) myFound.characters[-1].appliedCharacterStyle = myCharStyle;

    }

app.findGrepPreferences = null;

Capture d’écran 2017-03-02 à 11.39.36.png

(^/) 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2017 Mar 02, 2017

Copy link to clipboard

Copied

This is not something you can just like that with InDesign's Grep. The Grep manager that Gert mentioned can't do that, don't know about Automatication's solution. If Michael's solution doesn't work for you, you can change italic formatting to text tags, so that this:

Review of Religions,

(where the comma is not italic) is rendered like this:

<i>Review of Religions</i>,

You can then search for (</i>)([[:punct:]]) and replace with $2$1 to move the punctuation inside the italics. Then you change the italic tags back to italic formatting. This method is described in detail in https://indesignsecrets.com/issues/issue-76-publish-anywhere. You'd do that again for bold and bold-italic. You can store the queries and rerun them. It's a method I've been using a lot, and it works well.

Peter

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 02, 2017 Mar 02, 2017

Copy link to clipboard

Copied

Peter, you're right. It cannot be done by either. I thought it could be chained, but no. The Grep manager and the MFC are useful solutions when grep queries can be executed one after the other. We use it a lot during layout of texts coming from Word.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 25, 2022 Aug 25, 2022

Copy link to clipboard

Copied

LATEST

I found a way,
Find: (?<!.)[:,;")!?%]|["(](?!.)

Find format: font style regular (or if you work with characterstyles, like I do chacacter style: [none])

 Change format: italic (or character-style: italic)

satzzeichen_SE.PNG

 

Explanation: It looks for every character in the list [:,;")!?%] that is preceded by any character that is not regular/has no character style OR every character in the second list ["(] that is followed by a character that is not regular/has no character style.

It's not perfect. I would like to optimize it so that it won't find brackets in which the text is not fully italic (e.g this text). But I couldn't find out how. It does work well enough though.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines