PDA

View Full Version : [SOLVED:] Entering zero-width space in regular expression as part of replacement string



ma_roberge
09-06-2016, 01:56 PM
I am writing a procedure with two parameters that will add a zero-width space (8203, U+200B) after the slashes to allow correct word wrap of URLs (something that Word ought to do by itself to avoid all those unacceptable wide spaces, especially in justified text):

.Text: ([0-9A-z]/)([0-9A-z])
.ReplacementText: \1*****\2 (the character should be inserted in place of the asterisks)

The search and replace works perfectly when I perform it in Word itself, but, for some reason, I cannot insert into the VBA editor the desired zero-width space; in Word, with paragraph marks visible, this shows as a square within a larger one. If I copy and paste the symbol from Word to the VBA editor, I get a question mark in my code, and I do not know the format that can (or must) be used to enter the character into the replacement string.

Thanks in advance for any help.

Paul_Hossler
09-06-2016, 03:59 PM
Try this, assuming the font supports Unicode (wide) characters




.ReplacementText: "\1" & ChrW(8203) & "\2"

ma_roberge
09-07-2016, 07:42 AM
Paul,

Thank you very much for your help; my problem is solved.