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

How to write \r and \Z in the same expression?

Advocate ,
Nov 20, 2024 Nov 20, 2024

Copy link to clipboard

Copied

For example, the following expression that looks for spaces at the beginning and end of a paragraph:
(^[[:blank:]]+)|([[:blank:]]+$)


I'm trying to add to this the case of end-of-article, end-of-table-cell spaces.
(^[[:blank:]]+)|([[:blank:]]+$)|([[:blank:]]+\Z)
The result failed.


But it's OK for you to separate two separate executions of ([[:blank:]]+\Z).

Translated with DeepL.com (free version)

TOPICS
Bug , Feature request , How to , Performance , Scripting

Views

243

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 ,
Nov 20, 2024 Nov 20, 2024

Copy link to clipboard

Copied

Allow them to be 2 separate GREP searches chained together in Find/ChangeByList script built into InDesign. Edit the FindChangeByList.txt textfile in the FindChangeSupport subfolder to write both searches. It already has a search to clean up trailing spaces. You could add a duplication that is adjusted to look at the beginning of the paragraph.

I made a version of this that does some 32 text cleanups and it is available on my website. If you want to use the built-in FindChangeByList, add this expression into the txt file:


grep {findWhat:"(?<=\\r)\\s"} {changeTo:""} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}
//Find all spaces preceded by a return and remove the space.


grep {findWhat:"\\s(?=\\r)"} {changeTo:""} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}
//Find all spaces followed by a return and remove the space.

Mike Witherell

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
Advocate ,
Nov 20, 2024 Nov 20, 2024

Copy link to clipboard

Copied

Thank you very much.
Can't the same regularity be realized?

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
Guide ,
Nov 20, 2024 Nov 20, 2024

Copy link to clipboard

Copied

Hi @dublove 

 

Try this:

(\h+)(?=\r|$)|^(?1)

 

In the above pattern, you could replace \h by a similar space metacharacter or class (e.g. \s[[:space:]], [ \t], etc), but \h is usually considered the safest for that purpose.

 

Best,

Marc

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
Advocate ,
Nov 29, 2024 Nov 29, 2024

Copy link to clipboard

Copied

Hi Marc ~

Thank you very much.
Can you explain what |^(?1) means?

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
Guide ,
Dec 04, 2024 Dec 04, 2024

Copy link to clipboard

Copied

quote

Can you explain what |^(?1) means?


By @dublove

 

Well,

| is the alternation operator,

^ is the start-paragraph assertion,

and (?1) is the actual fun part of the GREP expression: it reproduces the literal pattern from the 1st capturing parenthesis, that is, (\h+) in my example:

(\h+)(?=\r|$)|^(?1)

But if you use a different expression in the 1st parenthesis, say (\s+), then (?1) will reflect that change. So it's a convenient way to "factor out" syntactic elements within a GREP pattern.

 

Best,

Marc

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
Guide ,
Dec 05, 2024 Dec 05, 2024

Copy link to clipboard

Copied

LATEST

Hi Marc,

 

Just Grep-curious! What about "\n" to be removed in the same time with "\h"?

 

Capture d’écran 2024-12-05 à 11.29.54.png

 

(^/)  The Jedi

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