Help with wildcards

interested_newbie
NewLounger
Posts: 8
Joined: 15 Oct 2023, 14:54

Help with wildcards

Post by interested_newbie »

Hi,

I am trying to use wildcards to make my formatting of a text easier, but so far have been frustrated in my efforts.

I am trying to find a wildcard that will automatically find all quotations in a text and automatically start a new paragraph with them. In addition, I would ideally want the quotations which start in the middle of a sentence not to do this, not to be put into a new paragraph.

Take this text for example:

Mr. Campbell, the minister of Essendean, was waiting for me by the garden gate, good man! He asked me if I had breakfasted; and hearing that I lacked for nothing, he took my hand in both of his and clapped it kindly under his arm.
“Well, Davie, lad,” said he, “I will go with you as far as the ford, to set you on the way.” And we began to walk forward in silence.
“Are ye sorry to leave Essendean?” said he, after awhile.
“Why, sir,” said I, “if I knew where I was going, or what was likely to become of me, I would tell you candidly. Essendean is a good place indeed, and I have been very happy there; but then I have never been anywhere else. My father and mother, since they are both dead, I shall be no nearer to in Essendean than in the Kingdom of Hungary, and, to speak truth, if I thought I had a chance to better myself where I was going I would go with a good will.”


I would ideally like it to look like this:

Mr. Campbell, the minister of Essendean, was waiting for me by the garden gate, good man! He asked me if I had breakfasted; and hearing that I lacked for nothing, he took my hand in both of his and clapped it kindly under his arm.

“Well, Davie, lad,” said he, “I will go with you as far as the ford, to set you on the way.” And we began to walk forward in silence.

“Are ye sorry to leave Essendean?” said he, after awhile.

“Why, sir,” said I, “if I knew where I was going, or what was likely to become of me, I would tell you candidly. Essendean is a good place indeed, and I have been very happy there; but then I have never been anywhere else. My father and mother, since they are both dead, I shall be no nearer to in Essendean than in the Kingdom of Hungary, and, to speak truth, if I thought I had a chance to better myself where I was going I would go with a good will.”


If anybody knew how to do this and would be able to help me, I would be extremely grateful. Thanks a lot and enjoy your day,

Daniel

User avatar
HansV
Administrator
Posts: 78795
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Help with wildcards

Post by HansV »

Welcome to Eileen's Lounge!

In your sample text, there already appears to be a paragraph break before each quote (except for those that start in the middle of a sentence).
Is that correct? If so, I'd increase the Space Before of the paragraphs (or even better, of the style).

Or are they manual line breaks?
Best wishes,
Hans

interested_newbie
NewLounger
Posts: 8
Joined: 15 Oct 2023, 14:54

Re: Help with wildcards

Post by interested_newbie »

Thanks a lot. Now you say it, I realise that they are line breaks. If I replace these with paragraphs, I think I should get the effect I am looking for.

That was simple and very helpful, thanks a million!

User avatar
HansV
Administrator
Posts: 78795
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Help with wildcards

Post by HansV »

You're welcome!
Best wishes,
Hans

interested_newbie
NewLounger
Posts: 8
Joined: 15 Oct 2023, 14:54

Re: Help with wildcards

Post by interested_newbie »

Just another question.

Is there any way to insert a page break before a word? For example, wherever I have the word "Chapter", I have been trying to insert a page break (the formatting is not uniform, so I cannot do it effectively the other way around, i.e. replace multiple paragraph breaks with a page break).

Would you know? Any help would be greatly appreciated.

User avatar
HansV
Administrator
Posts: 78795
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Help with wildcards

Post by HansV »

Press Ctrl+H to activate the Replace dialog.
Click 'More >>' to display the search options.
Tick the check box 'Use wildcards'.
Enter the following in the 'Find what' box:

([!^m])(Chapter)

And in the 'Replace with' box:

\1^m\2

Click 'Replace All'.

The [!^m] means: anything but a page/section break. This ensures that:
- The word Chapter at the very beginning of the document won't have a page break inserted before it.
- If the word Chapter already has a page break before it, we won't add another one.
Best wishes,
Hans

interested_newbie
NewLounger
Posts: 8
Joined: 15 Oct 2023, 14:54

Re: Help with wildcards

Post by interested_newbie »

Thanks a million, that's extremely helpful.

So I could normally just write (Chapter) or Chapter in the Find section, if I didn't care about the first chapter or chapters already with a page break?

What does "\1^m\2" mean?

User avatar
HansV
Administrator
Posts: 78795
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Help with wildcards

Post by HansV »

When using wildcards, you can specify parts of the find text by enclosing it in parentheses. In ([!^m])(Chapter), they are:

([!^m]) specifies [!^m], i.e. any character but a page break, as the first part.
(Chapter) specifies the word Chapter as the second part.

In the 'Replace with' box, we can refer to the first part as \1, to the second part as \2, etc. So [f]x\1^m\2[/fx] means:
The first part, i.e. the last character before the word Chapter, followed by a page break, followed by the second part, i.e. the word Chapter.
That way, we insert a page break between that character and the word Chapter.

If you don't care about inserting a page break before the first Chapter, or about duplicating page breaks, it would be simpler:
In 'Find what':
Chapter
in 'Replace with':
^mChapter
Best wishes,
Hans

interested_newbie
NewLounger
Posts: 8
Joined: 15 Oct 2023, 14:54

Re: Help with wildcards

Post by interested_newbie »

I am obviously living up to my name ;)

While I have you, perhaps I could impose and ask another question.

I have been trying to automatically make all chapter titles into headings and have had reasonable success so far with

Find box: chapter*

Replace box: chapter* + in style click on "heading 1".

All the chapters are now headings, but instead of "chapter 5" as a heading, I have "chapter* 5". What am I doing wrong?

Thanks a million again, it is very helpful for me.

interested_newbie
NewLounger
Posts: 8
Joined: 15 Oct 2023, 14:54

Re: Help with wildcards

Post by interested_newbie »

Ingenious the explanation by the way, very simple but very useful! :D

User avatar
HansV
Administrator
Posts: 78795
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Help with wildcards

Post by HansV »

Do you use the word Chapter in other locations than in the chapter titles? If not, you can simply use Chapter in the 'Find what' and 'Replace with' boxes.
Best wishes,
Hans

interested_newbie
NewLounger
Posts: 8
Joined: 15 Oct 2023, 14:54

Re: Help with wildcards

Post by interested_newbie »

Yes, but I would like the number that follows the chapter to also be included in the heading, e.g. chapter 5.

User avatar
HansV
Administrator
Posts: 78795
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Help with wildcards

Post by HansV »

Since Heading 1 is a paragraph style, it will be applied to the entire paragraph that contains the word Chapter, not just to that word.

Before.png
After.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

interested_newbie
NewLounger
Posts: 8
Joined: 15 Oct 2023, 14:54

Re: Help with wildcards

Post by interested_newbie »

Thank you so much, that has helped me an incredible amount :thankyou: