Skip to main content
New Participant
May 28, 2020
Question

GREP: find numbers in a range

  • May 28, 2020
  • 6 replies
  • 7864 views

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.

This topic has been closed for replies.

6 replies

pixxxelschubser
Community Expert
May 28, 2020

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

FRIdNGE
Inspiring
May 28, 2020

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!

pixxxelschubser
Community Expert
May 28, 2020

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

😉

pixxxelschubser
Community Expert
May 28, 2020

😄

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)

2)

3)

FRIdNGE
Inspiring
May 28, 2020

You have an error on B) and C)!  Read the code more carefully!  😉

FRIdNGE
Inspiring
May 28, 2020

Aha! … Damn it! Totally right! … Corrected! …  😉

pixxxelschubser
Community Expert
May 28, 2020

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)

 

pixxxelschubser
Community Expert
May 28, 2020

I would do something like that:

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

FRIdNGE
Inspiring
May 28, 2020

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"! …

David Popham
Participating Frequently
May 28, 2020

Try the following:

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

pixxxelschubser
Community Expert
May 28, 2020

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? …

David Popham
Participating Frequently
May 28, 2020

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.