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

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

Guide ,
Nov 20, 2024 Nov 20, 2024

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

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

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

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

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

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

Hi Marc ~

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

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

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

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