Copy link to clipboard
Copied
Hi, am trying to execute InDesign's default find/change AppleScript script to fix many formatting issues in a large document. One of them is occurences of a two-digit dollar figure followed by a comma (eg. "$10,") that needs to be changed to have no comma.
Using GREP I can pick it up by finding "\$\d\d," but when I replace it with "\$\d\d" I get the actual string "\$\d\d". IE. "$10," becomes "\$\d\d" rather than "$10". Am I misundersting how the 'change' part of GREP works? Can any one advise?
FYI the line in the find/change support .txt doc is:
| grep | {find what:"\\$\\d\\d,"} | {change to:"\\$\\d\\d"} | {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} | Remove commas after prices. |
...which includes extra backslashes to escape the backslashes that are part of the GREP expression.
Any help much appreciated!
Thanks.
In Grep Pallette, use the below syntax to find two or multiple digit dollar figure followed by a comma text,
Find what: (\$\d+),
Change to: $1
Vandy
Copy link to clipboard
Copied
I think it's replace with $1.
Copy link to clipboard
Copied
Thanks for your reply, but that replaces the found text with the string "$1." or "$1" (not sure if the full stop was meant to be part of the string, but the result is the same). Same outcome using the find/change script or the find/change dialog within InDesign.
Copy link to clipboard
Copied
Hi Luke....,
see the screen shot & try ....

thanks
shil...
Copy link to clipboard
Copied
Thanks, although this appeared to pick up any number followed by a comma, not just those preceded by a dollar sign. I might have messed up the syntax though as yours and Vandy's response came in al most simultaneously and I was keen to try both as quickly as possible. Same question goes for you though, why does your find/change work with the change to as "$1" when mine simply changed the found text to the actual strong "$1"?
Copy link to clipboard
Copied
Now I'm thinking I somehow did something wrong when using your method. The two posts below suggested changing to "$1" and it worked in both instances, but not yours. I suspect the error might be at my end! Thanks.
Copy link to clipboard
Copied
It's easier to do this:
Find what: (?<=\$\d\d),
Change to: nothing (i.e. leave the field empty)
This is more efficient as you needn't use references. (?<=\$\d\d) is a lookbehind, so in effect the Find what expression says "if a comma is preceded by $ and two digits, then delete the comma."
If you use CS6 8.0.0 or earlier, by the way, you'll have problems with \$ as it will find only the first $. Better use [$] or \x24 to find dollar symbols.
Peter
Copy link to clipboard
Copied
Thanks very much for your help, that's great. Out of interest, can the find statement be modified to be broader, say if a comma is preceded by a $ and any number of digits? Is it (?<=\$\d+),
I'm really struggling to get to grips with how GREP statements work. Thanks again.
Copy link to clipboard
Copied
No, unfortunately lookbehinds don't work with variable-length strings. That's the case with all GREP implemantations, not just InDesign's. You can sort of get around it by using or-constructs, but they soon become unmanageable. Here's an example (split and indented just for clarity, you would need to write all this on one line):
(
(?<=\$\d)
|
(?<=\$\d\d)
|
(?<=\$\d\d\d)
)
,
This one says "if a comma is preceded by $ and a digit OR by $ and two digits OR by $ and three digits, then . . ." As you understand, if you need to allow up to six or seven digits, possibly thousand separators too, then lookbehinds become unpracticable.
>I'm really struggling to get to grips with how GREP statements work.
Try this: http://oreilly.com/catalog/9780596156008/
Peter
Copy link to clipboard
Copied
Thanks for your reply, I really appreciate it. Will definitely check out that book.
Copy link to clipboard
Copied
In Grep Pallette, use the below syntax to find two or multiple digit dollar figure followed by a comma text,
Find what: (\$\d+),
Change to: $1
Vandy
Copy link to clipboard
Copied
Thanks, that worked perfectly. But here's what I don't understand: when I did change "\$\d\d," to "$1" it just replaced with the actual string "$1", but when I used your method, it worked fine. Apart from the difference in the 'find what' string, what makes your method work?
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more