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

GREP reference; need end-of-paragraph expression

New Here ,
Mar 28, 2008 Mar 28, 2008

Copy link to clipboard

Copied

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
TOPICS
Scripting

Views

1.7K

Translate

Translate

Report

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 ,
Mar 28, 2008 Mar 28, 2008

Copy link to clipboard

Copied

End-of-paragraph is a '$' sign (only and always at the end of your expression). Perhaps your GREP got confused because of your using dollars everywhere -- did you mean to search for a dollar sign? In that case, use '\$' (escaped). That means you can ditch all the '\r' and '\n' in your search.
You should also escape the other special character in your search: the period. As it is, it'll pick up
i any
character, and that probably will be replaced with nothing. Use '\.' to search for a literal period if you want to.

It seems you've heard about the '+' operator (one or more of the last expression) but didn't quite understand it 🙂 It's not necessary to search for "0+|00+" (i.e., a '0' followed by more
b or
two zeros followed by more).
Stringing everything together with "|" (ORs) is not necessary to include 'either with a space or without' -- you can use the Zero-or-Once operator '?'. Just a little handier would be Zero-or-Umpteen -- the '*'. Where '\s?' would only include zero or one space, '\s*' includes zero or any other number.

Putting it all together, I think this should work nicely:

>\.?0+\s*$

In English: Zero or one period, followed by any number of zeros (including a single one), followed by any number of spaces (including none), followed by the end of a paragraph. And that includes end-of-story (additionally, end-of-table-cell as well).

As it is, this will also strip off the zeros for numbers such as "10" (one without a decimal point). It takes a bit more work to ignore these, although it still is possible.

By way of answer to your question, there
i is
a special End-of-Story marker: '\Z'. That works like the '$' code, but it matches the real end of story
i only.

Votes

Translate

Translate

Report

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
LEGEND ,
Mar 29, 2008 Mar 29, 2008

Copy link to clipboard

Copied

This might work better:
(\.[1-9]+)0+\s*$
and replace with $1

(Although that wont get 8.000)
Harbs

Votes

Translate

Translate

Report

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 ,
Mar 29, 2008 Mar 29, 2008

Copy link to clipboard

Copied

Thanks, Harbs -- nice & simple. If you use
>(\.[1-9]*)0+\s*$

i.e.,
i zero
or more of 1..9 following the period, that'll all 0s after that. Sounds like the OP meant this.

Votes

Translate

Translate

Report

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 Beginner ,
Mar 29, 2008 Mar 29, 2008

Copy link to clipboard

Copied

//
find = (\d+)(((\.[1-9]+)(0+))|(\.(0+)))(?=\s*)
replace = $1$4

jxswm

Votes

Translate

Translate

Report

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 ,
Mar 31, 2008 Mar 31, 2008

Copy link to clipboard

Copied

What's wrong with

find: 0+$
replace with: "" (i.e. nothing)

Peter

Votes

Translate

Translate

Report

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
LEGEND ,
Apr 01, 2008 Apr 01, 2008

Copy link to clipboard

Copied

> What's wrong with
>
> find: 0+$
> replace with: "" (i.e. nothing)
>
That will get any number ending in zeros, even integers (like 100). He
only wants to strip them off decimals.

Harbs

Votes

Translate

Translate

Report

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 ,
Apr 02, 2008 Apr 02, 2008

Copy link to clipboard

Copied

Ah, that's what's wrong with it. Back to Jongware.

Peter

Votes

Translate

Translate

Report

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 ,
Apr 04, 2008 Apr 04, 2008

Copy link to clipboard

Copied

Thank you all for your replies. Unfortunately I probably didnt think of all the different scenarios. JXSWMs solution came the closest to what I was trying to achieve. What I failed to explain was all the different combos I needed to take care of. Example:
I would like to take the following
1.0000 x 1.2000
3.1200 x 4.1230
1.2090 x 1.2001
And turn it into this:
1 x 1.2
3.12 x 4.123
1.209 x 1.2001

JXSWMs query wiped out the double zeros in 1.2001, making it 1.21
Jongwares script didnt get the 000[space] scenario.(as in 1.0000 x)
My script was very inefficient and also didnt get the 0000[space] scenario.

I could add 0\s|00\s|000\s|0000\s to my original query but that would not be very elegant.

advice please?

Votes

Translate

Translate

Report

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 ,
Apr 04, 2008 Apr 04, 2008

Copy link to clipboard

Copied

It's probably easiest to do this in two steps. First:

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

to delete dots followed by zeroes (1.0000). Then the other cases:

find: (\.[\d]+?)0+\b
change to: $1

This way, you still understand the expressions an hour later.

Peter

Votes

Translate

Translate

Report

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 ,
Apr 04, 2008 Apr 04, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Apr 04, 2008 Apr 04, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 ,
Apr 04, 2008 Apr 04, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 Beginner ,
Apr 04, 2008 Apr 04, 2008

Copy link to clipboard

Copied

(\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)+)

Votes

Translate

Translate

Report

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 Beginner ,
Apr 04, 2008 Apr 04, 2008

Copy link to clipboard

Copied

OR:

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

This will be match all not number after the numbers.

Votes

Translate

Translate

Report

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 ,
Apr 05, 2008 Apr 05, 2008

Copy link to clipboard

Copied

jxswm,

Your GREPs don't find 1.2090

Peter

Votes

Translate

Translate

Report

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 Beginner ,
Apr 05, 2008 Apr 05, 2008

Copy link to clipboard

Copied

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

jxswm

Votes

Translate

Translate

Report

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 ,
Apr 05, 2008 Apr 05, 2008

Copy link to clipboard

Copied

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 :-)

Votes

Translate

Translate

Report

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 ,
Apr 05, 2008 Apr 05, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 Beginner ,
Apr 05, 2008 Apr 05, 2008

Copy link to clipboard

Copied

(\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

Votes

Translate

Translate

Report

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 ,
Apr 05, 2008 Apr 05, 2008

Copy link to clipboard

Copied

LATEST
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

Votes

Translate

Translate

Report

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