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

GREP expression help needed

Participant ,
Nov 22, 2023 Nov 22, 2023

I need to find currency and figgures, and flip the order throughout the report. 

 

Example: 

4,000 AED  to be   AED 4,000

200 AED  to be  AED 200

TOPICS
How to , Scripting , Type
1.2K
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

correct answers 2 Correct answers

Guide , Nov 22, 2023 Nov 22, 2023

Find: ([\d,]+)(\h)(\u+)

Replace by: $3$2$1

 

(^/)  The Jedi

Translate
Guide , Nov 22, 2023 Nov 22, 2023

OK!

 

(\d[\d,.]+\d)(\h)(\u+)

 

(^/)

Translate
Guide ,
Nov 22, 2023 Nov 22, 2023

Find: ([\d,]+)(\h)(\u+)

Replace by: $3$2$1

 

(^/)  The Jedi

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 ,
Nov 22, 2023 Nov 22, 2023

Thank you Jedi! 

but what if I have a decimals in some numbers? 

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
LEGEND ,
Nov 22, 2023 Nov 22, 2023

What kind? @FRIdNGE already included comma - [\d,]

 

But you can replace it with 

 

[\d\.,]

 

You need to "escape" "." as alone it means "any character" so you need to add "\" before "." = "\."

 

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 ,
Nov 22, 2023 Nov 22, 2023

Here are some examples of numbers

2,000,000 AED

5,340.76 AED

200.15 AED

 

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 ,
Nov 22, 2023 Nov 22, 2023

([\d,.]+)(\h)(\u+)

 

(^/)

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 ,
Nov 22, 2023 Nov 22, 2023

It did not work Jedi

Now it's finding only capital letters at start of paragraphs 🙂 

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 ,
Nov 22, 2023 Nov 22, 2023

Are you sure?

 

Capture d’écran 2023-11-22 à 13.24.58.pngCapture d’écran 2023-11-22 à 13.25.14.png

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 ,
Nov 22, 2023 Nov 22, 2023

Sorry it works, but it's finding only capital letters at start of paragraphs as well. 

Screen Shot 2023-11-22 at 4.41.38 PM.png

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 ,
Nov 22, 2023 Nov 22, 2023

OK!

 

(\d[\d,.]+\d)(\h)(\u+)

 

(^/)

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 ,
Nov 22, 2023 Nov 22, 2023

Thanks a lot! 

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
LEGEND ,
Nov 22, 2023 Nov 22, 2023
LATEST
quote

OK!

 

(\d[\d,.]+\d)(\h)(\u+)

 

(^/)


By @FRIdNGE

 

Is "." in [] treated as "." or as "any character" ?

 

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
Community Expert ,
Nov 22, 2023 Nov 22, 2023

Just to build on @FRIdNGE's work a little, you can reduce the possibility of false positives by explicitly listing the standard currency codes (assuming you are using these):

 

(\d[\d\.,]+\d)\h(AED|AFN|ALL|AMD|ANG|AOA|ARS|AUD|AWG|AZN|BAM|BDS|BDT|BGN|BHD|BIF|BMD|BND|BOB|BRL|BSD|BTN|BWP|BYN|BZD|CAD|CDF|CHF|CLP|CNY|COP|CRC|CUP|CVE|CZK|DJF|DKK|DOP|DZD|EGP|ERN|ETB|EUR|FJD|FKP|GBP|GEL|GGY|GHS|GIP|GMD|GNF|GTQ|GYD|HKD|HNL|HRK|HTG|HUF|IDR|ILS|IMP|INR|IQD|IRR|ISK|JEP|JMD|JOD|JPY|KES|KGS|KHR|KID|KRW|KWD|KYD|KZT|LAK|LBP|LKR|LRD|LSL|LYD|MAD|MDL|MGA|MKD|MMK|MNT|MOP|MRO|MRU|MTL|MUR|MVR|MWK|MXN|MYR|MZN|NAD|NGN|NIO|NOK|NPR|NZD|OMR|PAB|PEN|PGK|PHP|PKR|PLN|PYG|QAR|RON|RSD|RUB|RWF|SAR|SBD|SCR|SDG|SEK|SGD|SHP|SLL|SOS|SRD|SVC|SYP|SZL|THB|TJS|TMT|TND|TOP|TRY|TTD|TWD|TZS|UAH|UGX|USD|UYU|UZS|VEF|VND|VUV|WST|XAF|XCD|XOF|XPF|YER|ZAR|ZMK|ZWL)

 

I prefer the extra level of specificity. Then after running it, I would use FridNGE's more open grep and manually search through and check the one's this one missed—quite possibly none—because that will also validate the currency codes!

- Mark

 

Note: the forum software told me that I couldn't include the code for Barbadian dollar, so I took it out, but you may like to put it back in. *shrugs*

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 ,
Nov 22, 2023 Nov 22, 2023

Thank you! 

But I found that there is a code for all currencies 

(\w+)

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
Community Expert ,
Nov 22, 2023 Nov 22, 2023

Sure, but that will also, incorrectly, target this text, for example:

The Company's 2023 AAA rating has suffered ...
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
LEGEND ,
Nov 22, 2023 Nov 22, 2023

I'm not an expert, and on my phone, but it should be a good start:

 

Find 

([\d,]+) ([A-Z]+)

 

Change to

($2) ($1)

 

The only thing I'm not sure is the 2nd part - how to make it "not greedy"... Unless, you always have "AED" - this exact string, only letters - always CAPS - or letters + numbers?

 

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 ,
Nov 22, 2023 Nov 22, 2023

Robert,

 

\h targets any space and tab.

 

Your "Change to" will replace:

 

200 AED

 

by:

 

(AED) (200)

 

So, remove the parenthesis to make your F/R work correctly here!  😉

 

Best,

(^/)

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
LEGEND ,
Nov 22, 2023 Nov 22, 2023
quote

So, remove the parenthesis to make your F/R work correctly here!  😉

 

Best,

(^/)


By @FRIdNGE

 

Right, forgot about that.

 

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