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

GREP: find numbers in a range

New Here ,
May 27, 2020 May 27, 2020

Copy link to clipboard

Copied

Using Find/Change GREP, I want to search a document to find all instances of numbers from 1-1575. To be clear: a "number" is a sequence of digits preceded and followed by something that isn't a digit. Is there a GREP phrase that will do that?

I have Googled this phrase and others like it to find an answer but none seem to directly answer this question.

TOPICS
How to

Views

5.0K

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
Enthusiast ,
May 27, 2020 May 27, 2020

Copy link to clipboard

Copied

Try the following:

\b([1-9]|[0-9]{2}|[0-9]{3}|1[0-5][0-7][0-5])\b

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 ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

Not:

 

\b([1-9]|[0-9]{2}|[0-9]{3}|1[0-5][0-7][0-5])\b

 

But:

 

\b([1-9]|[1-9][0-9]|[1-9][0-9]{2}|1[0-4][0-9]{2}|[15[0-6][0-9]|157[0-5])\b  [ previous version ]

\b([1-9]|[1-9][0-9]|[1-9][0-9]{2}|1[0-4][0-9]{2}|15[0-6][0-9]|157[0-5])\b

 

It could be simplified to:

 

(?x)\b(  [1-9][0-9]{0,2}  |  1[0-4][0-9]{2}  |  [15[0-6][0-9]  |  157[0-5]  )\b  [ previous version ]

(?x)\b(  [1-9][0-9]{0,2}  |  1[0-4][0-9]{2}  |  15[0-6][0-9]  |  157[0-5]  )\b

 

[ According to me, the using of numbers ranges ("[x-y]") makes the Grep syntax … easier to be written and more readable for the users/readers, even if [0-9] = \d!  ðŸ˜‰ ]

 

(^/)  The Jedi

 

[ edited for clarification by moderator ]

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 ,
May 27, 2020 May 27, 2020

Copy link to clipboard

Copied

Hi @David_Popham,

nice try. But unfortunately your grep will not catch the whole range.

 

@earwig99,

can you show us an meaningful example text, please. What characters are normally before and behind your range af numbers from 1-1575 ? Are these numbers always in between your text? Or standalone in table cells? Do you have combinations in your document - eg az1521 or negative numbers eg -573 maybe? Or? Or? …

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
Enthusiast ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

Ah, yep. The last pattern in my option is going to miss quite a few numbers. A good reminder not to answer questions right before going to bed.

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 ,
May 29, 2020 May 29, 2020

Copy link to clipboard

Copied

Yes David,

this is one of the rare cases where a full review is required. And then you can catch the whole range and you get no false negative hits.


However, to avoid false positive hits, it is imperative to get more information from the OP about all other possible combinations of numbers in the document. This is the only way to be able to say with certainty whether further checks are necessary or not.

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
New Here ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

Hi - sorry, only just seen this exchange. In this self-referential sentence, the number 328 is an example; another example is -742; a third is (928); a fourth and fifth are the ends of the range 1-1575; a sixth is flibbertygibbet339omigawd; but I don't want to find 326157522! In that (preceding) sentence, I want to find 328, 742, 928, 1, 1575, and 339.  In other words, as I said in the original post, I want to find every number from 1-1575. I just wanted to be clear that I didn't want to find any sequence of digits within a larger number outside that range. And, no, I don't care if the number is positive or negative. 

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
New Here ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

LATEST

Sorry, I should add: thanks for responding to my original query! 

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 ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

I would do something like that:

(?<!-)\<([1-9]|\d{2,3}|1[0-4]\d{2}|15[0-6]\d|157[0-5])\>

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 ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

Hi Pixxxel!  ðŸ˜‰

 

(?<!-)\<([1-9]|\d{2,3}|1[0-4]\d{2}|15[0-6]\d|157[0-5])\>

 

will catch, e.g., "00", "001 or "099"! …

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 ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

Aha! … Damn it! Totally right! … Corrected! …  ðŸ˜‰

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 ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

Yes.

Hi Obi,

that's why I asked the OP for a better explanation. And in real that shouldn't be a problem.

😉

 

But IMHO the middle part of your variant is wrong.

[1-4][0-9]{3} will catch all numbers from 1000 till 4999.

 

And this is out of the wished range.

 

Kindly regards

(sent from phone)

 

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 ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

😄

Guess which style is in use:

A)

\b([1-9]|[0-9]{2}|[0-9]{3}|1[0-5][0-7][0-5])\b

B)

\b([1-9]|[1-9][0-9]|[1-9][0-9]{2}|1[0-4][0-9]{2}|[15[0-6][0-9]|157[0-5])\b

C)

(?x)\b( [1-9][0-9]{0,2} | 1[0-4][0-9]{2} | [15[0-6][0-9] | 157[0-5] )\b

D)

(?<!-)\<([1-9]|\d{2,3}|1[0-4]\d{2}|15[0-6]\d|157[0-5])\>

 

1)

range_1-1575_01.png

2)

range_1-1575_02.png

3)

range_1-1575_03.png

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 ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

You have an error on B) and C)!  Read the code more carefully!  ðŸ˜‰

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 ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

I know.

But this is your error. I only copied your code.

 

And your have changed it again five minutes ago. And you have now changed your posting for the 6th time. Please do not this. Simple add a new answer instead of editing your previuos posting multiple times.

Thank you

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 ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

Pixxxel, I just want to tell you it was a "coquille" (in French) - I forgot to remove this single bracket that had no reason to be in my code! … and I would have appreciated you indicate it to me!

It's absolutely not a code syntax error like the two other ones (yours and mine)!

[end of game for me, sorry!]

Thanks to update your 2nd screenshot!

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 ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

So ist es. Nachdem du die überflüssige Klammer entfernt hast, funktioniert dein Grep ebenfalls wie gewünscht.

 

Sollte sich der OP in den nächsten Tagen noch einmal melden, werde ich vielleicht auch noch den Screenshot Nr. 2 in meinem letzten Beitrag auf den aktuellen Stand bringen. Oder du erstellst selbst einen und postest ihn.

 

Ich gehe jetzt erst einmal ins Bett.

Gute Nacht und viele Grüße

😉

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