Copy link to clipboard
Copied
Hi everyone,
I'm facing an issue with InDesign find and replace and hoping someone here can help.
Trying to insert a discretionary hyphen before a specific pattern in the text. I use a positive lookahead regex pattern (?=\w+~_) to find the target position and insert '~-', but this only works for the first occurrence in a text frame. To work around this, I tried switching the approach to use a matching regex: (\w+~_) and then use the replace string as ~-$0~k. However, when I give changeAll with this, I'm losing the character formatting (e.g., bold text gets reverted to Roman). Interestingly, when I use change one at a time, the formatting is preserved.
Has anyone encountered this issue or found a workaround to keep the formatting intact while using changeAll? Or Am I missing something in the positive lookahead pattern.
Thanks in advance for any suggestions!
Copy link to clipboard
Copied
The problem seems to be that you replace chunks of text while all you want to do ir insert some text.
In your case, you can insert the discr hyphen at the insertion point before the em rule:
Find: (?=~_)
Change: ~k
The Find string is just the lookahead, in other words, the insertion point before what's matched by the lookahead.
Copy link to clipboard
Copied
Hi @Peter Kahrel,
Thanks for your response. But I need to insert the discrestionary hyphen in the begining of the word and after the Em-dash.
Thanks,
Sathish
Copy link to clipboard
Copied
In that case you use a lookbehind: (?<=~_)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now