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

Help with some GREP strings

Community Beginner ,
Jul 24, 2018 Jul 24, 2018

Copy link to clipboard

Copied

Hi,

I'm trying to figure out two GREPs.

1. I have a lot of prices in my document that I need to mass replace. They look like this: XX.ZZ, where XX is numeral part, and ZZ is decimal part, with dot between them. How I can select only the numeral part? Please note that sometimes it has a space to divide thousands (for example 12 000.30 , or 3 322.99), and in this case the space also needs to be selected.

2. I need to select a bunch of text until a specific text appears. It basically looks like this:

The whole text from "DED6601..." up until "...19.00" is one text field, and I need to select only the part in the red rectangle. I've tried to just do normal text search, where I left "Search for" empty, and select only by format, and it works, but when I do replace - it also removes the end of paragraph, and changes the style of "Produkty komplementarne". So then I experimented with sth like this:

^.*?(Produkty komplementarne|$)(?m)

And additionally I add format requirements. And it works, although sometimes the text has couple paragraphs, and when I do mass replace - it makes couple replaces instead of one.

Any ideas how I could fix that?

D.

Views

906

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

correct answers 1 Correct answer

Mentor , Jul 25, 2018 Jul 25, 2018

1.  I’d try this:

[\d ]+(?=\.)

2. Script from this thread

Votes

Translate

Translate
Guide ,
Jul 25, 2018 Jul 25, 2018

Copy link to clipboard

Copied

1. to find the numbers, try this grep and let us know:

(\d+)[ \.]*?(\d+)[\.](\d+)

2. about your second question:

do you have a soft or hard return before Produkty komplementarne: ?

Can we see the same screenshot but with Hidden Characters?

(Choose Type > Show Hidden Characters)

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

Copy link to clipboard

Copied

1.  I’d try this:

[\d ]+(?=\.)

2. Script from this thread

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 ,
Jul 25, 2018 Jul 25, 2018

Copy link to clipboard

Copied

Thanks, I'll check the second point in a moment!

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 ,
Jul 25, 2018 Jul 25, 2018

Copy link to clipboard

Copied

winterm​

Ad. 1 it worked perfectly!

Ad. 2 I struggle to use this code, because it seems to do much more than I need. Is there any way to get the actual GREP line from it, just for selecting the proper part.

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 ,
Jul 25, 2018 Jul 25, 2018

Copy link to clipboard

Copied

For your second request... Maybe this can do it:

Find: (?s)^[\u\d]+\r\K.+(?=Produkty komplementarne:)

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

Copy link to clipboard

Copied

john_problem  ha scritto

....How I can select only the numeral part? ...

I probably did not understand correctly your question
my grep finds also the decimal part.

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 ,
Jul 25, 2018 Jul 25, 2018

Copy link to clipboard

Copied

1. Yup, but fortunately winterm​ answered my question!

But I actually will use the GREP you provided too for different cases, I just need to modify it a bit more, and maybe you could help me on that? I need it to only select the price if:

- it doesn't have letters in the same string (only numbers, space, and dot)

- it has one or two decimal numbers, not more

Basically there are other number in the project with dot in the middle, and they are not prices and I need to skip them.

2. This is how it looks with the hidden chars:

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 ,
Jul 25, 2018 Jul 25, 2018

Copy link to clipboard

Copied

Unfortunately it doesn't. When I use the GREP u suggested it does select the text, but it also selected the end of paragraph, so after I use mass replace it changes from this:

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

Copy link to clipboard

Copied

try to add \r before Produkty komplementarne:)

(?s)^[\u\d]+\r\K.+(?=\rProdukty komplementarne:)

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 ,
Jul 25, 2018 Jul 25, 2018

Copy link to clipboard

Copied

John, what are you doing with the text when selected? Only formatting it with a style or something else?

Seems that you have added «test»in your change to field.

If you only want to format the selected text, leave the change to empty and set your format.
If you want to add something use $0 and your added content along with format.

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 ,
Jul 25, 2018 Jul 25, 2018

Copy link to clipboard

Copied

Hey,

@Jean-Claude

Yes, I'm mass replacing the text with something else. That's why I used "test".

@vladan

It works, but... There's this one little thing that I forgot to mention in my original post. The GREP that I was using before (^.*?(Produkty komplementarne|$)(?m)) had problems, but it had one advantage  - it also selected the fitting text if it didn't ended with "Produkty komplementarne". And when I use your GREP - it only works if the "produkty komplementarne" text appears, otherwise it just ignores the text completely. So below is an example.

Is it a way to modify the GREP to select both cases? I was trying to add |$ like in my original script, but it didn't helped.

Sorry for not being more clear about it...:(

EDIT - to be even clearer - I use your GREP with very specifing formatting search, so I basically need sth like this - select all text that fits the formatting, and end the selection before "produkty komplementarne", and if that doesn't appear, then select until the formatting fits.

DM

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 ,
Jul 25, 2018 Jul 25, 2018

Copy link to clipboard

Copied

This maybe...

(?s)^[\u\d]+\r\K(.+(?=\rProdukty komplementarne:)|.+$)

But if you are looking for a specific styling... which seems to be different than the DED7515 or the paragraph after, why not just use this:

(?s).+ With formatting attributs


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 ,
Jul 25, 2018 Jul 25, 2018

Copy link to clipboard

Copied

LATEST

@Jean-Claude

I ended up doing sth like this:

.+(?=\rProdukty komplementarne:)|.+$

And it seems to work perfectly! Thanks for all your help!!!

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