12 Replies Latest reply on Jun 4, 2014 1:08 AM by Mr. S. Sanjay kumar

# GREP expression to remove trailing zeros?

Hi,

I have to find and change multiple entries of trailing zeros. Please find sample below to understand type entries need to be change.

1.00              -> 1

0.01200         -> 0.12

4.50              -> 4.5

0.0040           -> 0.004

Please help me how can i use grep to find and change in CS6

Thanks in Advance.

Sanjay

• ###### 1. Re: GREP expression to remove trailing zeros?

I believe this will work:

Find (?<=[\.\d])0+(?=\s) and replace with nothing

• ###### 2. Re: GREP expression to remove trailing zeros?

Hi Peter

(?<=[\.\d])\.?0+(?=\S\s)

• ###### 3. Re: GREP expression to remove trailing zeros?

This also works

(?<=(.|1-9))0+\>

• ###### 4. Re: GREP expression to remove trailing zeros?

Hi Eugene,

Not with 150.00 and NOT with ID CC: apparently, bug with \> (already encountered about another recent post)!

• ###### 5. Re: GREP expression to remove trailing zeros?

Obi-wan Kenobi wrote:

Hi Peter

(?<=[\.\d])\.?0+(?=\S\s)

Oh yes. Forgot the case where you need to delete the decimal point.

There's a major problem with these expressions, though, if there isn't a decimal point in the number. It truncates any whole number ending in 0, too.

• ###### 6. Re: GREP expression to remove trailing zeros?

Error:

(?<=[\.\d])\.?0+(?=\s)

• ###### 7. Re: GREP expression to remove trailing zeros?

I'm not sure it's possible to do this in a single step if there are numbers with trailing zeros and no decimal part.

You could search for \.\d+ first and assign a character style, then run the previous expression with the scope limited to the character style.

• ###### 8. Re: GREP expression to remove trailing zeros?

Well I can't debug every version of InDesign - it works in CS5.5

• ###### 9. Re: GREP expression to remove trailing zeros?

the \> picks up the decimal point following a 0 as the end of a word, which is why I used \s.

• ###### 10. Re: Re: GREP expression to remove trailing zeros?

Peter,

Right! In 3 steps (text in black)

1/ Exclusion if no decimal part:

Find: ,?(?<![\.\d])(\d+)(?![\.\d])

Replace: color X

2/ Treatment:

Find: (?<=[\.\d])\.?0+(?=\s)

Search Format: color black

Replace: nothing

3/ Treatment:

Search Format: color X

Replace Format: color black

Seems to work. To be validated!

• ###### 11. Re: GREP expression to remove trailing zeros?

It's is working fine, Thanks

• ###### 12. Re: GREP expression to remove trailing zeros?

This is working fine. But thanks for your help