Hello Everyone,
I hope you’re safe and keeping yourselves indoors as much as possible.
I have a scenario where I have to change the position of the comma between the numbers. It goes like this:
INPUT (Comma Separator as in India [2,2,3]):
$6,737
$6,64,559
$6,89,566
$26,38,400
$8,85,67,337
$5,17,11,889
$20,14,52,513
$95,35,32,752
OUTPUT (Comma Separator as in US/UK [3,3,3]):
$6,737
$664,559
$689,566
$2,638,400
$88,567,337
$51,711,889
$201,452,513
$953,532,752
Basic approach:
GREP Find/Change 1:
Find What: (\$)(\d)(\d),(\d)(\d),(\d)(\d),(\d\d\d)
Change to: $1$2$3$4,$5$6$7,$8
GREP Find/Change 2:
Find What: (\$)(\d),(\d)(\d),(\d)(\d),(\d\d\d)
Change to: $1$2$3,$4$5$6,$7
GREP Find/Change 3:
Find What: (\$)(\d)(\d),(\d)(\d),(\d\d\d)
Change to: $1$2,$3$4$5,$6
GREP Find/Change 4:
Find What: (\$)(\d),(\d)(\d),(\d\d\d)
Change to: $1$2$3$4,$5
I created and merged all these four GREP queries in a single JavaScript using the ChainGREP and it worked like a charm.
The problem with this approach is that it is limited, every time when there’s an extra digit, I have to update the code. With the above codes, I’m able to manage 9 digit numbers. I still have one more Found instance available ($9), so I can go up to ten digits, but after that, I will have to work manually.
Is there any better way to achieve this. Any ideas will be appreciated.
Thanks
Masood