Skip to main content
dublove
Legend
November 20, 2024
Question

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

  • November 20, 2024
  • 1 reply
  • 736 views

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)

1 reply

Mike Witherell
Community Expert
Community Expert
November 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
dublove
dubloveAuthor
Legend
November 20, 2024

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

Marc Autret
Legend
November 21, 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