Highlighted

GREP: find numbers in a range

New Here ,
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

1.4K

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

GREP: find numbers in a range

New Here ,
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

1.4K

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 27, 2020 0
16 Replies 16
Adobe Community Professional ,
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

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 27, 2020 0
Most Valuable Participant ,
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? …

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 27, 2020 0
Adobe Community Professional ,
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.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 28, 2020 1
Most Valuable Participant ,
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.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 29, 2020 0
New Here ,
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.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 03, 2020 0
LATEST
New Here ,
Jun 03, 2020

Copy link to clipboard

Copied

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

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 03, 2020 0
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 ]

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 28, 2020 0
Most Valuable Participant ,
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])\>

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 28, 2020 1
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"! …

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 28, 2020 0
Most Valuable Participant ,
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)

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 28, 2020 0
May 28, 2020

Copy link to clipboard

Copied

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

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 28, 2020 0
Most Valuable Participant ,
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)

2)

3)

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 28, 2020 0
May 28, 2020

Copy link to clipboard

Copied

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

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 28, 2020 0
Resources
Learn and Support
Resources
Features