0
GREP reference; need end-of-paragraph expression
New Here
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/td-p/1147569
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
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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147570#M278409
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.
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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147571#M278410
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
(\.[1-9]+)0+\s*$
and replace with $1
(Although that wont get 8.000)
Harbs
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147572#M278411
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.
>(\.[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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Beginner
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147573#M278412
Mar 29, 2008
Mar 29, 2008
Copy link to clipboard
Copied
//
find = (\d+)(((\.[1-9]+)(0+))|(\.(0+)))(?=\s*)
replace = $1$4
jxswm
find = (\d+)(((\.[1-9]+)(0+))|(\.(0+)))(?=\s*)
replace = $1$4
jxswm
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147574#M278413
Mar 31, 2008
Mar 31, 2008
Copy link to clipboard
Copied
What's wrong with
find: 0+$
replace with: "" (i.e. nothing)
Peter
find: 0+$
replace with: "" (i.e. nothing)
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147575#M278414
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
>
> 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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147576#M278415
Apr 02, 2008
Apr 02, 2008
Copy link to clipboard
Copied
Ah, that's what's wrong with it. Back to Jongware.
Peter
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Really Randy
AUTHOR
New Here
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147577#M278416
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?
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?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147578#M278417
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
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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147579#M278418
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
find: \.0+$
change to: (nothing)
To ensure that numbers such as 4.0300 and 5.0002 are dealt with correctly.
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Really Randy
AUTHOR
New Here
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147580#M278419
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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147581#M278420
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
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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Beginner
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147582#M278421
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)+)
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)+)
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Beginner
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147583#M278422
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.
(\d+)(((\.[1-9]+)(0+))|(\.(0+)))(?=\D+)
This will be match all not number after the numbers.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147584#M278423
Apr 05, 2008
Apr 05, 2008
Copy link to clipboard
Copied
jxswm,
Your GREPs don't find 1.2090
Peter
Your GREPs don't find 1.2090
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Beginner
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147585#M278424
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
REPLACE = $1$4
THIS WILL trim LEFT the end ZEROS(0);
jxswm
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Really Randy
AUTHOR
New Here
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147586#M278425
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 :-)
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 :-)
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Explorer
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147587#M278426
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
> 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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Beginner
,
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147588#M278427
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
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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
LATEST
/t5/indesign-discussions/grep-reference-need-end-of-paragraph-expression/m-p/1147589#M278428
Apr 05, 2008
Apr 05, 2008
Copy link to clipboard
Copied
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
/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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

