Jong:
Superb explanation!
I was afraid of mixing text/grep because I was getting inside darker waters: java scripting.
(that file text used to run the find.change by list is the proof...)
But was trying with grep as this can combine more characters in a search, for example finding space before point, period, semicolon, etc. Or space after ( or before)... Was trying to reduce too many operations in an script and pursuing a cleaner homework.
Thank you very much for your time.
@Laurent: heh heh. After that long story I was still paying attention to the original question...
Mariana:
... as this can combine more characters in a search, for example finding space before point, period, semicolon, etc. Or space after ( or before)... |
Yes, that's possible with GREP. Try this for the first one:
grep {findWhat:" ([.,:;])"} {changeTo:"$1"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Remove space before period et al.
(Remember the script needs TABS between the sections, as in the original file.)
This one is a bit challenging. Actually, the period is a special character in GREp (it stands for "any character"), so normally you would need to escape it:
(space)\.
to search for a space followed by a period. However, the square brackets [...] define an OR group, and that removes the magic properties from the period. Apparently, there is no use for a wildcard character in an OR group! (That would be something like, "The following characters are allowed: a comma, a colon, any at all, a semi-colon ...")
There is a more advanced way to remove spaces like these. You want to look for spaces which are followed by any of these characters, and replace them with nothing. That would be
{findWhat:" (?=[.,:;])"} {changeTo:""}
You can try this in the interface to see it works.
---
The second can be done using the Unicode value for an ellipsis ("\x{2026}" -- another notation than in the regular Text find), or with the special escape code "~e". Yup -- there is another escape character. The backslash is used by GREP itself, but GREP does not understand InDesign's own special characters -- page breaks, smart single and double quotes, Indent-To-Here, em dashes, and a few others. They can also be inserted from the menu on the right side of the Find field. These characters need a tilde, so InDesign can "translate" them internally to something GREP can use, and GREP never sees them. Since the tilde is nothing special for Javascript, you can safely insert only one in the script data file ...
To remove a space before or after an ellipsis, you could use this:
grep {findWhat:" ?~e ?"} {changeTo:"~e"}
... but in this case it may again be simpler to stick to regular text mode (where you would use "^e" for the ellipsis, by the way).