Skip to main content
Known Participant
December 11, 2024
Question

Grep reverse character order

  • December 11, 2024
  • 2 replies
  • 467 views

I have an InDesign file with headers of bank names in Chinese.

The problem is that the Chinese characters need to be reversed.

Is there a way to create a GREP expression to search for word(s) of any length, and then reverse the entire string of characters? I will be restricting the search to a given paragraph style that has only been applied to the bank names.

For example, if the string in question is ABCD, the desired result is DCBA.

This topic has been closed for replies.

2 replies

Joel Cherney
Community Expert
Community Expert
December 12, 2024

The Jedi's solution is slick, as usual, but I fear it won't work in your case, as that solution is built around searching for \u, meaning A Single Uppercase Letter, and that won't capture any Chinese characters. I suppose one could replace each instance of \u with something like [\x{2E80}-\x{9FBB}] which should capture most Chinese characters. (There are exceptions, like for full-width punctuation. If you wind up using a solution like this, there are easy ways to test to find out if all of your glyphs are being caught by the Unicode-value regex I provided above, like applying a highlight character style to visually review, which can be deleted from the document once you've done your QA.)

 

But, if you don't mind my asking... why? Why are bank names mirror-reversed in your document? I'd suspect that maybe they've accidentally have some right-to-left text setting applied, which could just be turned off. That'd be less risky than trying to reverse glyph order. 

 

 

FRIdNGE
December 13, 2024

Hi Joel,

 

My starting point (without more info) was F/R based on Capitals but it could be any char including its font style!

(just replacing "\u" by ".")

Here, I've used the "Adobe Myungjo Std" font:

 

 

(^/)

FRIdNGE
December 12, 2024

… Supposing the Starting point is "ABCD" (in capitals) and the Arrival point is "DCBA"!

 

3 simple Regex!

 

In my sample, the biggest word is "EFGHIJKLMN" that has 10 chars. So you will need to play:

 

Regex "_Fridnge_1" once

Regex "_Fridnge_2" 10 times (until no match!)

Regex "_Fridnge_3" once

 

Of course, with a tool as Multi-Find/Change, you just need 1 click!

 

 

(^/)  The Jedi