Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

GREP find/change problem

New Here ,
Dec 13, 2012 Dec 13, 2012

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.

TOPICS
Scripting
4.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Dec 13, 2012 Dec 13, 2012

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

Translate
LEGEND ,
Dec 13, 2012 Dec 13, 2012

I think it's replace with $1.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 13, 2012 Dec 13, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 13, 2012 Dec 13, 2012

Hi Luke....,

see the screen shot & try ....

Screen Shot 2012-12-14 at 05.49.18.png

thanks

shil...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 13, 2012 Dec 13, 2012

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"?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 13, 2012 Dec 13, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 14, 2012 Dec 14, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 15, 2012 Dec 15, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 16, 2012 Dec 16, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 16, 2012 Dec 16, 2012
LATEST

Thanks for your reply, I really appreciate it. Will definitely check out that book.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 13, 2012 Dec 13, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 13, 2012 Dec 13, 2012

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines