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

Grep Style / Find Change

Guest
Mar 21, 2022 Mar 21, 2022

Copy link to clipboard

Copied

I am doing a catalog and and I have multiple variable 

I need your GREP expertise
Ii have a document with variable numbers thatI need the format changes:
 
"From 3 years to 6 years"
change "3 - 6" (no quotes)
 
From 3 years to 6 years
3 - 6
 
but the "numbers" are different though out the cataloge
Is there a way to say FIND From "any number" years to "any number" years
and change to "any number" - "any number" ?
 
Any find and change advice would be appreciated!
TOPICS
How to , Print , Type

Views

254

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

Community Expert , Mar 21, 2022 Mar 21, 2022

Sorry, missed that.

[Ff]rom\s(\d+)\syears\sto\s(\d+)\syears

Votes

Translate

Translate
Community Expert ,
Mar 21, 2022 Mar 21, 2022

Copy link to clipboard

Copied

In the Find/Change GREP field:

\d is any digit.

(\d) could be recalled in the replace field as $0, or $1, or $2

Make sure you set an EN dash; not a hyphen; between ranges of numbers.

And so: 

Find what: (\d) years to (\d)

Change to: $1~=$2

Change All

Mike Witherell

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 ,
Mar 21, 2022 Mar 21, 2022

Copy link to clipboard

Copied

Mikes answer assumes an ordinary typed space.

I would perhaps use (\d+)\syears\sto\s(\d+) which will find other types of spaces as well.

I also prefer to change to $1~<~=~<$2 which adds a thin space on either side of the en-dash

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 ,
Mar 21, 2022 Mar 21, 2022

Copy link to clipboard

Copied

Also forgot to mention that the use of \d+ picks up numbers that are more than one digit, in case you have those, too.

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
Guest
Mar 21, 2022 Mar 21, 2022

Copy link to clipboard

Copied

now it looks like this

Ages From 0 - 4  years 

it needs to be :

Ages From 0 - 4  years

 

Getting there! 

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 ,
Mar 21, 2022 Mar 21, 2022

Copy link to clipboard

Copied

Okay, instead of just (\d+)\syears\sto\s(\d+) use [Ff]rom\s(\d+)\syears\sto\s(\d+) which will pick up the "from" and eliminate it with the following space. The [Ff] class will pick it up whether or not it is capitalized.

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
Guest
Mar 21, 2022 Mar 21, 2022

Copy link to clipboard

Copied

i still need to remove the "years at the end "

Ages 3–6 years ?

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 ,
Mar 21, 2022 Mar 21, 2022

Copy link to clipboard

Copied

LATEST

Sorry, missed that.

[Ff]rom\s(\d+)\syears\sto\s(\d+)\syears

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