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

How do I apply paragraph styles without affecting other lines that follow?

Guide ,
Jun 02, 2025 Jun 02, 2025

Clicking “Replace” several times seems to be normal.
But click Replace All, and all the text in the back becomes H2.

This question has been bothering me for a long time. I seem to have done it in two parts before.

How to solve it?

 

Do I need to do this in two steps?
Apply the style first, then delete the null?

Can't it be just one step?

Is it possible to implement this on regular expressions?

(^\s*)(^[A-Z]\.)(\h*)(.+\r)(^\s*)

01.png02.png

TOPICS
Bug , Feature request , How to , Scripting
538
Translate
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 3 Correct answers

Community Expert , Jun 02, 2025 Jun 02, 2025

Generally, when searches include \r hard returns, the paragraph style gets applied to both paragraphs. So when you GREP search, it is better to Match... with a Positive Lookahead for a hard return. That way it sees it without including/selecting it.

Translate
Community Expert , Jun 02, 2025 Jun 02, 2025

@dublove  Oh sorry, I didn't understand correctly.

 

I wouldn't recommend doing it in one operation, just because it is much easier to construct the grep and understand the consequences if you do in two, simpler operations.

 

But if you must do it in one go, maybe something like this should remove leading or trailing paragraphs from the target paragraph:

(?:^|(?<=\r)\r)([A-Z]\..*)(?:\r(?=\r)|$)

And replace with:

$1

 

The critical issue is that your grep doesn't match anything in the surrounding

...
Translate
Community Expert , Jun 03, 2025 Jun 03, 2025

@dublove It *does* delete the line after (and before):

find-change-demo-2025-06-03.gif

 

But as I said, it is better to do this in two operations, removing the empty paragraphs first.

- Mark

Translate
Community Expert ,
Jun 02, 2025 Jun 02, 2025

Click with the text tool once into the text to apply the style to a single paragraph, select several paragraphs to apply text to several paragraphs. Don't select the frame and apply the style. It will apply the style to all text of an unlinked text frame.

Translate
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
Guide ,
Jun 02, 2025 Jun 02, 2025

Hi Willi Adelberger

You don't seem to understand what I'm saying.

Translate
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 02, 2025 Jun 02, 2025

Willi missed the GREP part it seems 😏

Translate
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 02, 2025 Jun 02, 2025

I cannot test right now on my phone but perhaps try this:

^[A-Z]\.

One problem is you are matching text into the next paragraph so it will be styled too. Also, to apply a paragraph style you only need to match *any* text in a paragraph. 
- Mark

Translate
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
Guide ,
Jun 02, 2025 Jun 02, 2025

I'm just giving an example, my main purpose is to illustrate:
Finding and applying styles when there are blank lines before and after, as well as deleting the blank lines, and how it doesn't affect the text that follows.

Translate
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 02, 2025 Jun 02, 2025

@dublove  Oh sorry, I didn't understand correctly.

 

I wouldn't recommend doing it in one operation, just because it is much easier to construct the grep and understand the consequences if you do in two, simpler operations.

 

But if you must do it in one go, maybe something like this should remove leading or trailing paragraphs from the target paragraph:

(?:^|(?<=\r)\r)([A-Z]\..*)(?:\r(?=\r)|$)

And replace with:

$1

 

The critical issue is that your grep doesn't match anything in the surrounding paragraphs because then they will have the paragraph style applied also. In the grep above I used lookarounds to "look into" the previous and next paragraphs without matching them (this is what @Mike Witherell described). I also used two non-capturing groups (?: ) just to keep it cleaner.

 - Mark

Translate
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
Guide ,
Jun 03, 2025 Jun 03, 2025

It just can't delete the empty line after it.
I'm still a little better with 2 steps:
Remove the blank line first, then apply the style.

Translate
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 03, 2025 Jun 03, 2025

@dublove It *does* delete the line after (and before):

find-change-demo-2025-06-03.gif

 

But as I said, it is better to do this in two operations, removing the empty paragraphs first.

- Mark

Translate
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
Guide ,
Jun 03, 2025 Jun 03, 2025

Sorry m1b.
I didn't seriously test your last reply and it turns out it really works, which is what I needed, thanks a lot.

You've solved another big problem.

Translate
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
Guide ,
Jun 03, 2025 Jun 03, 2025

In fact, the situation with my Chinese version of the example is much more complicated.
There may be multiple blank lines before and after, and the blank lines are not just \r.
The place where a line break is needed may also be in the line.
I need to decide whether to keep the period ([。\r]+) .

I am now able to remove the blank lines first, and then apply the style to realize it.

(^\s*)(^[一二三四五六七八九十百千万零〇]+)([、\h]+)([^。\r]+?)([\r。]+)((^\s*)*)


My original regular was such that it contained all possible blank lines. and the three endings of A, B, and C. (\r)|(。\r)|(。) .

I tried to use the same syntax used in (? :[。\r]+(^\s*)*).

Or even (? =^)
It doesn't seem to be unattainable.

 

The full file is here

06.png07.png

Translate
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 04, 2025 Jun 04, 2025

Screenshot 2025-06-05 at 13.16.58.png

@dublove You cannot do this in one operation, because even if you break into two paragraphs, they will both be styled, which is not what you want.

Translate
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
Guide ,
Jun 03, 2025 Jun 03, 2025

@m1b 

I didn't find a pattern.
But I seem to sense it:
If you want the back row to be unaffected, then (? 🙂 part has to have no intersection with the front.

Sometimes the ([a\r])(? : ) may be correct. But if it is ([a\r]+)(? : ) when it is, it affects the back rows again. Amazing.

It seems like the front and back have to be really cut apart to work.

 

Also, it seems (. +? \r) is valid, while (. +?) (\r) just might affect the lines after it.

 

(?:^|(?<=\r)\r) Does the top group have to be this one, this one doesn't seem to be able to contain multiple lines.

Come up with a simple sample.

0666.png

Translate
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 04, 2025 Jun 04, 2025

@dublove I don't understand why you are making this so hard for yourself. Tell us why you can't just find and replace all the empty lines first? This is the normal way to do it.

 

For example, find what:

^\s*$\r

and change to: 

(nothing)

 

remove-empty-lines.gif 

 

This makes the next step much easier I think.

- Mark

Translate
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
Guide ,
Jun 04, 2025 Jun 04, 2025
LATEST

I'm trying to do 3 things with one expression: replace, delete blank lines, and apply styles.
I seem to have succeeded.
Many thanks.

Translate
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
Guide ,
Jun 03, 2025 Jun 03, 2025

This can take care of deleting multiple lines behind it without affecting it, but multiple lines in front of it can't be set up again.

(Chapter 7.+?) (\r)((? :(^\s*)*)|^)

$1\r

 

Translate
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
Guide ,
Jun 03, 2025 Jun 03, 2025
(? :^|(^\s*)) (Chapter 7.+?) (\r)((? :(^\s*)*)|^)
$2\r

Can this be optimized: can multiple lines be selected without affecting subsequent lines?

Translate
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
Guide ,
Jun 03, 2025 Jun 03, 2025

But it's weird that you only replace one at a time. Removing blank lines and applying styles can be done at the same time.

Translate
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 02, 2025 Jun 02, 2025

Generally, when searches include \r hard returns, the paragraph style gets applied to both paragraphs. So when you GREP search, it is better to Match... with a Positive Lookahead for a hard return. That way it sees it without including/selecting it.

Mike Witherell
Translate
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
Guide ,
Jun 02, 2025 Jun 02, 2025

@Mike Witherell 

I probably know what you mean, we can use (? =\r).
That is, you can't apply styles and remove blank lines at the same time.
That seems to be the only way to do it.

Translate
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
Guide ,
Jun 03, 2025 Jun 03, 2025

Hi @Mike Witherell 

How about this Match... What exactly does with a Positive mean, I'm trying to find a pattern in the @m1b  answers but I'm failing.

It seems (? 🙂 is critical, and |^ is also critical


Is it not universally applicable?

 

Translate
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 02, 2025 Jun 02, 2025

Hi @dublove , It sounds like this might be a case for the Object Styles Options’ > Paragraph Styles > Apply Next Style, which lets you repeat a loop of multiple Paragraph Styles with one click:

 

Screen Shot 8.pngScreen Shot 9.png

 

The Paragraph Styles’ Next Style setting creates the loop:

 

Screen Shot 11.pngScreen Shot 12.png

 

 

Translate
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
Guide ,
Jun 02, 2025 Jun 02, 2025

@rob day 

Not saying otherwise, I'm just giving an example.
How to apply styles while deleting blank lines without affecting the text that follows.

Translate
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