3

Indesign CS5.

I'm trying to perfect a regular expression to quickly replace the single-space from raw text to the EN space. I'm using the following:

(\w)([.!?])(['"]{0,1}) {1,}(['"]{0,1})(\u)

Replacing to:

$1$2$3~>$4$5

This should have captured and replaced the space with an EN space the following tests:

work. To
work! To
work." To
work.' 'To
work." "To

etc. I recognize it's not perfect as work.' "To would get through it, but that would be picked up in the editing sweeps. Please ignore that and similar conditions.

My problem is the replacement is coming out as...

work. $5o

The RegEx is finding text perfectly. If it finds work." "To, it replaces the space with an EN-space perfectly. Anything else isn't replacing correctly.

It appears that the (['"]{0,1}) expressions, since they're capturing nothing, are not having their relevant $# (e.g., $3) variable set. However, if that's the case, I expected to see work. $4$5o as the replacement for the work. To test.

Is there a workaround for this, or am I condemned to running a series of RegEx replacements?

4

If you need to change a regular space \s for an EN space I think is more simple:

(?<=\.|!|"|')\s(?=.|"|')

search al the regular spaces \s preceded by a dot \. , !, " or ' and behind a character ., " or '

and change it for an EN space

~>

enter image description here


Actually the second part is redundant, because " and ' are also characters, it must be:

(?<=\.|!|"|')\s(?=.)

If the rule is the \s behind a letter or " or ' :

(?<=\.|!|"|')\s(?=\u|\l|"|')

If the letter is always an uppercase :

(?<=\.|!|"|')\s(?=\u|"|')

enter image description here

  • This looks promising, I'll be back after I've tested it. Note that you can't use the whitespace character (\s) because it matches the end-of-paragraph, so \s{1,} will collapse paragraphs. that's why I'm using a simple space (which, in my case, is predictable). – JBH Jan 25 at 19:06
  • Answer updated. – Danielillo Jan 25 at 19:11
  • I'm using (?<=\.|!|"|') {1,}(?=\u|\l|"|'), but it's matching work" to, which it cannot do. I'll try your last RegEx in your current answer. – JBH Jan 25 at 19:14
  • Nope. (?<=\.|!|"|')\s(?=\u|"|') matches end-of-paragraph and collapses paragraphs. (?<=\.|!|"|') {1,}(?=\u|"|') fixes that problem, but it's still matching work" to, which it cannot do. The [.?!] preceding the space between sentences is mandatory. – JBH Jan 25 at 19:16
  • 1
    We have a winner! You must replace \s with {1,} (there's a single space preceding that left brace) or end-of-paragraph markers are captured and the paragraphs collapsed, but I sincerely appreciate your help working around InDesign's weakness! Thanks! – JBH Jan 25 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.