Skip to main content
Known Participant
March 28, 2008
Question

GREP reference; need end-of-paragraph expression

  • March 28, 2008
  • 18 replies
  • 2227 views
GREP reference; need end-of-paragraph expression

I'm doing a canned GREP search to delete all trailing zeros. So if I have a number like 8.2500, it changes it to 8.25.
I have the code to find zeros leading up to a space, line break, and paragraph return but I can't find the expression for an end of paragraph. With hidden characters on, it looks like a hash ( # ).

Does anyone know what this is?

If anyone knows a more elegant way to do this, please advise. Here's what I have:

0+$|00+$|000+$|0000+$|.0000+$|0+\s|00+\s|000+\s|0000+\s|.0000+\s|0+\n|00+\n|000+\n|0000+\n|.0000+\n|0+\r|00+\r|000+\r|0000+\r|.0000+\r
This topic has been closed for replies.

18 replies

Peter Kahrel
Community Expert
Community Expert
April 6, 2008
X,

/g is a switch in JavaScript GREP, but the OP wanted scripted Indesign. In fact InDesign's UI (and scripted GREPs) default to /g.

Peter
Known Participant
April 5, 2008
(\d+)(((\.\d*[1-9])(0+))|(\.(0+)))(?=\s)

this will be better than \D?

OR:
(\d+)(((\.\d*[1-9])(0+))|(\.(0+)))(?=\D)

OR: THIS WILL MATCH END OF THE STORY OR CELL END
(\d+)(((\.\d*[1-9])(0+))|(\.(0+)))(?=(\D|\Z))

jxswm
Known Participant
April 5, 2008
This GREP search:
FIND = (\d+)(((\.\d*[1-9])(0+))|(\.(0+)))(?=\D?)
REPLACE = $1$4

turns this:
1.0000 x 1.2000
3.1200 x 4.1230
1.2090 x 1.2001

into this:
1x 1.2000
3.12x 4.1230
1.209x 1.2001

deleting the spaces before the x and missing the trailing zeros before the line breaks or paragraph returns

almost there, I can't tell you guys how much I appreciate (and learn from) your efforts on this forum :-)
Known Participant
April 5, 2008
really_randy@adobeforums.com wrote:

> deleting the spaces before the x and missing the trailing zeros before the line breaks or paragraph returns
>
> almost there, I can't tell you guys how much I appreciate (and learn from) your efforts on this forum :-)

I don't recall what the notation is for a GREP search and replace, but you need
to have it operate globally.

In raw JS regex it would look like:
txt = txt.replace(/(\d+)(((\.\d*[1-9])(0+))|(\.(0+)))(?=\D?)/g, "$1$4");

where the "g" means to replace all occurrences.

-X
Known Participant
April 5, 2008
FIND = (\d+)(((\.\d*[1-9])(0+))|(\.(0+)))(?=\D?)
REPLACE = $1$4
THIS WILL trim LEFT the end ZEROS(0);

jxswm
Peter Kahrel
Community Expert
Community Expert
April 5, 2008
jxswm,

Your GREPs don't find 1.2090

Peter
Known Participant
April 4, 2008
OR:

(\d+)(((\.[1-9]+)(0+))|(\.(0+)))(?=\D+)

This will be match all not number after the numbers.
Known Participant
April 4, 2008
(\d+)(((\.[1-9]+)(0+))|(\.(0+)))(?=\s+)

this assume at least one space(includeing hard return) after the numbers;

if maybe no space after the number, but a x:
(\d+)(((\.[1-9]+)(0+))|(\.(0+)))(?=(\s|x)+)
Peter Kahrel
Community Expert
Community Expert
April 4, 2008
So much for reflection. Step one didn't do anything because it works only for numbers at the end of a paragraph ($). What is required is "at word boundary" (\b). Here's the correct expression:

Find: \.0+\b
change to: (nothing)

>this is harder than I thought it would be

It often works out like that. In your case, the complication is that sometimes the decimal separator should be deleted, sometimes not.

Peter
Known Participant
April 4, 2008
Step 2 did the trick for the 1.2001 scenario but step one didn't do anything, this is harder than I thought it would be.
Peter Kahrel
Community Expert
Community Expert
April 4, 2008
On reflection, the first step should be this:

find: \.0+$
change to: (nothing)

To ensure that numbers such as 4.0300 and 5.0002 are dealt with correctly.

Peter