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

GREP style to add a colon

Engaged ,
Jun 13, 2024 Jun 13, 2024

Copy link to clipboard

Copied

I have a document with Chapter headings (eg 'Chapter One') and what I want is to add to the Chapter Heading style a GREP expression that counts/misses the first two words and then adds a colon, ie making it 'Chapter One: '

Can that be done with GREP or am I asking the impossible?

TOPICS
EPUB , How to

Views

336

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

correct answers 2 Correct answers

Community Expert , Jun 13, 2024 Jun 13, 2024

Fairly easily, although I have to say the subject line looks like something that belongs in a medical forum. 🙂

 

Would it be much easier, though, to just do a quick search for "Chapter" in the heading style, then type in the colon? That would probably take less time than copying a GREP style from here, even.

 

I don't think a GREP or Line style will do it; it would have to be a GREP search and replace. So... pretty much same either way.

 

But this should do it:

JamesGiffordNitroPress_0-1718297742361.png

Note there's no space at the end

...

Votes

Translate

Translate
Community Expert , Jun 13, 2024 Jun 13, 2024

I can't guess why it would go backwards. 😛

 

There is probably a way to combine the two searches, but the simple solution to the hyphenated words would be to change the GREP string to (borrowing from MJ's model here)

Chapter\s\w+-\w+

 

ETA: And here's the combined string: Chapter [\w|-]+

 

I recommend Peter Kahrel's excellent book GREP in InDesign as a worthwhile reference to have at hand.

Votes

Translate

Translate
Community Expert ,
Jun 13, 2024 Jun 13, 2024

Copy link to clipboard

Copied

Fairly easily, although I have to say the subject line looks like something that belongs in a medical forum. 🙂

 

Would it be much easier, though, to just do a quick search for "Chapter" in the heading style, then type in the colon? That would probably take less time than copying a GREP style from here, even.

 

I don't think a GREP or Line style will do it; it would have to be a GREP search and replace. So... pretty much same either way.

 

But this should do it:

JamesGiffordNitroPress_0-1718297742361.png

Note there's no space at the end of the GREP string.


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋

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 ,
Jun 13, 2024 Jun 13, 2024

Copy link to clipboard

Copied

Many thanks for responding. Strangely, this GREP expression selects the next-to-last of 28 Chapter headings and then goes backwards through the headings despite my having 'Forward' checked - but it does then add the colon. That would be OK but there is another issue: from twenty onwards the number becomes 'Chapter Twenty-One' etc and the expression treats Twenty-One as two words. So the change becomes 'Chapter Twenty:-One'. Is there a way to treat a hyphenated word as one word? Sorry if I'm stretching this to breaking point!

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 ,
Jun 13, 2024 Jun 13, 2024

Copy link to clipboard

Copied

I can't guess why it would go backwards. 😛

 

There is probably a way to combine the two searches, but the simple solution to the hyphenated words would be to change the GREP string to (borrowing from MJ's model here)

Chapter\s\w+-\w+

 

ETA: And here's the combined string: Chapter [\w|-]+

 

I recommend Peter Kahrel's excellent book GREP in InDesign as a worthwhile reference to have at hand.


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋

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 ,
Jun 13, 2024 Jun 13, 2024

Copy link to clipboard

Copied

Thanks so much for that valuable help - still going to the last heading and going backwards with every 'Find Next' - but it works!

I will look out Peter Kahrel's book for more information.

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 ,
Jun 13, 2024 Jun 13, 2024

Copy link to clipboard

Copied

I don't think Grep Style or Nested Style would work for you, as they can only style the content and not add or remove content. You would have to use the regular find/change route in my opinion. But we would need to think of a way to restrict this only to the headings so search for the text as well the the style applied over the text. So the grep would be simple like

Find What :- (Chapter\s+\w+)

Replace With :- $1:

Find Format :- The name of the applied style

-Manan

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 ,
Jun 13, 2024 Jun 13, 2024

Copy link to clipboard

Copied

@m5heath

 

Do you have a separate - dedicated - ParaStyle applied to those Chapter Headings?

 

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 ,
Jun 13, 2024 Jun 13, 2024

Copy link to clipboard

Copied

Yes I do - why do you ask?

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 ,
Jun 13, 2024 Jun 13, 2024

Copy link to clipboard

Copied

LATEST
quote

Yes I do - why do you ask?


By @m5heath

 

Sorry, I thought that you have only Chapter One, etc. and you want to add ":" at the end of the paragraph - then you could use "$".

 

But after re-reading your post - you have something else after that, right? 

 

So you want to insert ":" after "number" and before the rest of the title, right? 

 

But what others suggested - will only work up to "nineteen" and then whole tens... 

 

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