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

GREP help

Explorer ,
Dec 12, 2016 Dec 12, 2016

Copy link to clipboard

Copied

I need help creating a GREP expression that will change the formatting of the first two words of a paragraph including a number that may or may not be following (e.g. Executive Director, Executive Director 2).

Any help would be appreciated.

Thanks much.

Views

607

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 , Dec 12, 2016 Dec 12, 2016

^.+?\s.+?\s\d?

Votes

Translate

Translate
Community Expert ,
Dec 12, 2016 Dec 12, 2016

Copy link to clipboard

Copied

^.+?\s.+?\s\d?

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
Explorer ,
Dec 12, 2016 Dec 12, 2016

Copy link to clipboard

Copied

Thanks Michael. It works perfectly, and it seems so easy, now that I see your formula.

Sure appreciate 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
LEGEND ,
Dec 13, 2016 Dec 13, 2016

Copy link to clipboard

Copied

Hi,

Not correct!

Capture d’écran 2016-12-13 à 10.35.25.png

[CS6+]

^(\H+)\h(?1)(\h(?=\d)\d)*

(^/) 

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
Explorer ,
Dec 13, 2016 Dec 13, 2016

Copy link to clipboard

Copied

Thanks for your reply Obi-Wan. I tested your GREP solution as well, and it also worked as expected.

Both your solution and Michael's solution behave the same (at least for my particular needs).

I'm eager to better understand GREP, so perhaps you could elaborate on why you feel your answer is correct, yet Michael's is not?

Thanks much.

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
LEGEND ,
Dec 13, 2016 Dec 13, 2016

Copy link to clipboard

Copied

Of course, Michael's code seems to work because his way is just enough in your case but, as I show, his code includes the "space" after the two words if no number (+ a space before) after them!

It could be problematic if you really need to find these two words and only them!

For instance, to make an index. In this case, the entry would include this "space"

If you wanna play with Grep, keep in mind that you'll need to be "precise"!

In any case, by accepting it, be aware of your "vagueness" and its possible consequences!

Another writing [I like!]:

^(\H+)\h(?1)(?>\h\d+)?

(^/) 

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 ,
Dec 13, 2016 Dec 13, 2016

Copy link to clipboard

Copied

Vagueness is kind of nice; you should try it sometime!

Obi-wan, in your GREP, I am not familiar with \H+. Does that mean "anything NOT a horizontal space one or more times", effectively a word? And what does h(?1) mean? Does that mean ONLY one space? And what does the third grouping mean?

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
LEGEND ,
Dec 13, 2016 Dec 13, 2016

Copy link to clipboard

Copied

Hi Michael,

To be really precise, we would use this:

^([\u\l]+)\h(?1)(?>\h\d+)?  

What does it mean?

^

--> Beginning of para

([\u\l]+)

--> any group of letters (no space, no number) -- see below why this writing is better!

\h

--> horizontal space (12 kinds of space + tab)

(?1)

--> that means the same kind of group (delimited by parenthesis) than the first one, so: ([\u\l]+)

(?>\h\d+)?

--> interesting writing: '(?> … )' is an "unbreakable" entity! with the "?" behind it, we means: "exist or not".

the targetted unbreakable group is: '\h\d+'

Using this code will avoid the problem you have with your code.

So, my code has 4 parts: a word + a space + a word (+ in option: a space + a number)

Using ([\u\l]+) will avoid to take in account:  "Director 2" at a para beginning.

Simple! 

I like precision but, I repeat, your code could be enough here! 

(^/)

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
Explorer ,
Dec 13, 2016 Dec 13, 2016

Copy link to clipboard

Copied

Obi-wan, thanks for the detailed breakdown and explanation. We all appreciate your "precision" and expertise.

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
LEGEND ,
Dec 13, 2016 Dec 13, 2016

Copy link to clipboard

Copied

LATEST

End of your training! 

Risky!

Capture d’écran 2016-12-13 à 18.54.38.png

Less risky!   ^(([\u\l-])+)\h(?1)(?>\h\d+(?!\H))?  …but really less readable! 

Capture d’écran 2016-12-13 à 18.54.51.png

… Just for fun!

(^/)

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 ,
Dec 13, 2016 Dec 13, 2016

Copy link to clipboard

Copied

Obi-wan, thank you for that instruction. I feel a bit smarter, now. My Vague-O-Meter needle has swung a bit to the right!

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