Copy link to clipboard
Copied
Is there a simple way (without scripts) to add in a hypen to a variable query?
For example, If I have an address say:
221B Baker Street
I want to be able to place a hyphen to instead make it:
221-B Baker Street
But my other variable is a Suite number such as:
1107 Brooklyn Boulevard, Suite A350
but this should also be hyphenated to:
1107 Brooklyn Boulevard, Suite A-350
Here is my Find What:
(\u\d)|(\d\u)
But I want to be able to change to:
$1-$2
But this doesn't work because of the variability. Any help?
1 Correct answer
\u\K\d|\d\K\u
-$0
(^/) The Jedi
Copy link to clipboard
Copied
The following substitution i.e. "change to" term should work
$1$3-$2$4
See the demo here
However, when trying in InDesign it is placing $3 and $4 literally while substitution. In order to force it to recognize $3 and $4 we need to have some other character between $1 and $3 and likewise between $2 and $4. I used a hairline space, you could try with some other whitespace character. The following works for me
Find What
(\d)(\u)|(\u)(\d)
Change To
$1~|$3-$2~|$4
-Manan
Copy link to clipboard
Copied
Is there no way to do this without the hairline space? My team does a lot of find/replaces, and I'd hate for their query to miss something because of a space added in
Copy link to clipboard
Copied
Using a single query I could not find any other way to make it work. As I showed in the demo, it works with other flavors of Regex implementation but InDesign's implementation does not work. I would await some grep geniuses on the forum to dish out a gem for this. For me, if the proposed solution does not fit the bill then it has to be done by using two separate queries.
-Manan
Copy link to clipboard
Copied
Thank you for your help. I will see if anyone else has an answer. Thanks!
Copy link to clipboard
Copied
\u\K\d|\d\K\u
-$0
(^/) The Jedi
Copy link to clipboard
Copied
Omg, this is exactly what I needed! I had no idea what /K was, but I might have to start usisng it more!!
Copy link to clipboard
Copied
Ahh, brilliant. I did think of using \K but the piece that I was missing is $0
-Manan

