Copy link to clipboard
Copied
I want to remove the space before some punctuation like sapce before period, space before coma, spce before question mark etc..
Can I remove the spaces with single GREP or indesign script.
Help me to find the right solution
Thanks in advance
Hello @Nousheeth,
You can do it with a single GREP like this...
Search for \s+([!,\.:;?]) and replace it with $1 (in the search, include whatever punctuation symbols you want inside the brackets, but remember to 'escape' reserved characters with a back slash \ like what's done with the period).
Regards,
Mike
I would use a class like [,.?!;:] with the punctuation you want to find as a look-ahead. You want to be careful, though, because there are legitimate places where space before punctuation is expected, quotation marks, parentheses and brackets for example, so the general class [[:punct:]] would not be a good idea, and some sorts of whitespace may also be legit, such as tabs and paragrap returns.
From Peter Kahrel's book I find that \p{space_separator} finds any white space other than tab or retu
...Copy link to clipboard
Copied
Hello @Nousheeth,
You can do it with a single GREP like this...
Search for \s+([!,\.:;?]) and replace it with $1 (in the search, include whatever punctuation symbols you want inside the brackets, but remember to 'escape' reserved characters with a back slash \ like what's done with the period).
Regards,
Mike
Copy link to clipboard
Copied
I don't think you need to escape the . inside a class.
Copy link to clipboard
Copied
> I don't think you need to escape the . inside a class.
Correct.
Copy link to clipboard
Copied
Thanks Mike
Its Working
Copy link to clipboard
Copied
I would use a class like [,.?!;:] with the punctuation you want to find as a look-ahead. You want to be careful, though, because there are legitimate places where space before punctuation is expected, quotation marks, parentheses and brackets for example, so the general class [[:punct:]] would not be a good idea, and some sorts of whitespace may also be legit, such as tabs and paragrap returns.
From Peter Kahrel's book I find that \p{space_separator} finds any white space other than tab or return {not sure if that covers both hard and soft returns, both of which I think you would want not to be included), so you might try starting with something like \p{space_separator}+(?=[,.?!;:])
I have not tested this...
Copy link to clipboard
Copied
Forgot you would want to replace with nothing.
Copy link to clipboard
Copied
> \p{space_separator} finds any white space other than tab or return
Correct.
Copy link to clipboard
Copied
Does it omit both forced line breaks and paragraph breaks?
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more