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?
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:
Note there's no space at the end
...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.
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:
Note there's no space at the end of the GREP string.
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!
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.
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.
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
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Yes I do - why do you ask?
Copy link to clipboard
Copied
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...