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

grep - reformat numbers

Participant ,
Jul 06, 2018 Jul 06, 2018

Hi all. In my work we do both English and French number formats. IE. $1,234 and 1 234 $, or 2.25% and 2,25 %. I've managed a grep f/c that changes the percents from E to F or F to E, but only if there's a decimal in the number. I cannot figure out how to change 5% (no decimal) without it finding the last digit before the percent sign (2.25%).

What would I add to my expression to find percentages that don't have decimals without also finding the last digit of a percentage with decimals? Note the number can be any number of digits long (IE 5%, 50%, 500%, 5000%, etc).

Thank you!

941
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
Mentor ,
Jul 06, 2018 Jul 06, 2018

grudgemom  wrote

What would I add to my expression

What expression? You did show any.

This one will find all % with or without preceding horizontal space, and insert Nonbreaking Space between the last digit and %:

find: \d\K\h?%

change to: ~S%

For CS6 and higher.

Not sure if this is what you’re looking for.

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
Guide ,
Jul 07, 2018 Jul 07, 2018

English --> French

Find: \d\K%

Replace by: ~S%

French --> English

Find: \d\K\h%

Replace by: %

Best,

Michel, for FRIdNGE

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
Participant ,
Jul 11, 2018 Jul 11, 2018
LATEST

I currently have 4 greps set up for this

English whole number percent to French:

Find: (\d+)% Change: $1 %

English decimal number percent to French:

Find: (\d+)\.(\d+)% Change: $1,$2 %

(I appear to have deleted my English whole number percent to French grep)

French decimal number percent to English:

Find: (\d+),(\d+) % Change: $1.$2%

-----------------------------------------

This also gets a little more difficult when I need to change dollar amounts to French. Those require moving the $ to the back end of the number, replacing commas with spaces and periods with commas. Fun!

For English to French I have:

Find: \x{0024}(\d+)\.(\d+) Change: $1,$2 \x{0024}

(I realize this doesn't take into account numbers over 999 - that's my next step)

I'm using the What the Grep script from Jongware to help breakdown all the pieces for me and it doesn't recognize \h or \K so that puts a kink in my process...

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