Copy link to clipboard
Copied
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*)
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.
@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
...@dublove It *does* delete the line after (and before):
But as I said, it is better to do this in two operations, removing the empty paragraphs first.
- Mark
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You don't seem to understand what I'm saying.
Copy link to clipboard
Copied
Willi missed the GREP part it seems 😏
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
@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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
@dublove It *does* delete the line after (and before):
But as I said, it is better to do this in two operations, removing the empty paragraphs first.
- Mark
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
@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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
@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)
This makes the next step much easier I think.
- Mark
Copy link to clipboard
Copied
I'm trying to do 3 things with one expression: replace, delete blank lines, and apply styles.
I seem to have succeeded.
Many thanks.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
(? :^|(^\s*)) (Chapter 7.+?) (\r)((? :(^\s*)*)|^)
$2\r
Can this be optimized: can multiple lines be selected without affecting subsequent lines?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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:
The Paragraph Styles’ Next Style setting creates the loop:
Copy link to clipboard
Copied
Not saying otherwise, I'm just giving an example.
How to apply styles while deleting blank lines without affecting the text that follows.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now