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)
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.
Copy link to clipboard
Copied
Thank you very much.
Can't the same regularity be realized?
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
Copy link to clipboard
Copied
Hi Marc ~
Thank you very much.
Can you explain what |^(?1) means?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Hi Marc,
Just Grep-curious! What about "\n" to be removed in the same time with "\h"?
(^/) The Jedi