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

GREP some, not all, parenthetical content

Community Beginner ,
Dec 16, 2016 Dec 16, 2016

Copy link to clipboard

Copied

Hi everyone.

I have a quick and wonderful GREP expression to apply an italicizing character style to parenthesis and the copy that falls within — 

\(.+?\)

Here's the kicker. Visually, I don't want to Italicize the content and parenthesis when it is an acronym.

Division of Motor Vehicle (DMV)  <-- no italics

Book title (extra detail)  <--- italics

I'm guessing the answer involves  \u\u+ which looks for two or more capital letters in a row.

So, it should, italicize parenthesis and content within, but not when the parenthetical material is all caps.

Any ideas? Thanks everyone.

-Bob

Views

549

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

Mentor , Dec 16, 2016 Dec 16, 2016

Try this:

\(.+[^\u]\)

it finds all occurrences except first here:

Division of Motor Vehicle (DMV)  <-- no italics

Book title (extra detail)  <--- italics

Book title (Extra Detail)  <--- italics

Book title (Division of Motor Vehicle)  <--- italics

Votes

Translate

Translate
Mentor ,
Dec 16, 2016 Dec 16, 2016

Copy link to clipboard

Copied

Try this:

\(.+[^\u]\)

it finds all occurrences except first here:

Division of Motor Vehicle (DMV)  <-- no italics

Book title (extra detail)  <--- italics

Book title (Extra Detail)  <--- italics

Book title (Division of Motor Vehicle)  <--- italics

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 Beginner ,
Dec 16, 2016 Dec 16, 2016

Copy link to clipboard

Copied

PERFECT! Thank you Winterm.

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

Copy link to clipboard

Copied

Sorry! Not correct.

Book title (Division of Motor Vehicle, DMV) 

\((?!\u+\)).+?\)

(^/) 

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
Mentor ,
Dec 16, 2016 Dec 16, 2016

Copy link to clipboard

Copied

Hey, Obi-wan, it's not a bullet-proof solution for tutorial, after all.

when it covers real-world OP's request, then it's enough...

why search for things that never happen?

"Less is More"

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

Copy link to clipboard

Copied

Only a bullet-proof grep with no false positive and no false negative hits is a good grep

winterm​,

keep cool. It's only a big sandbox.

btw please replace the + in your own grep in post #1 with +? for this following case which is never happens:

Book title (Division of Motor Vehicle)  Book title (extra detail)

Friendly regards

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

Copy link to clipboard

Copied

Keep Cool!  Do you really understand what you mean with:

\(.+[^\u]\)

You only say that you italicize all content between parenthesis whose last char is not a capital!!  [pixxxel ( )  is totally right about +?]

So:

(in US)

… won't be taken by your code! … but not:

(in Fr)

……

When I read Bob's question:

… "I don't want to Italicize the content and parenthesis when it is an acronym."

That simply means:

\((?!\u+\)).+?\)

Bob wants to italicize all content between parenthesis only if this content is not a group of capitals!

… so, only if the "entering" parenthesis is not followed by capitals and a "closing" parenthesis!!

(^/) 

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
Mentor ,
Dec 17, 2016 Dec 17, 2016

Copy link to clipboard

Copied

Do you really understand what you mean...

Yes, I do. Agreed, one may find such approach rather strange, but it works on OP samples. I listed cases it covers - don't you find it fair enough? That said, I have learned not answer the questions I wasn't asked. Your life experience may be different.

So: (in US) … won't be taken by your code!

So what? It's not here in the samples OP provided. I guess it's possible to invent scenarios which even Your smart code won't cover - then you'll need even more gorgeous one, and that's no surprise.

Pixxxel's addition is useful to restrict the GREP greediness. Seems like it's not the case in OP's text, so I omitted it. Would there be any harm of adding it? No!

Your codes cover much wider area, still aren't something worth to save for future reference. It's still kind of "use it once and throw away".

IMHO, nobody's really right or wrong here, it's just a matter of POV, so I find this further discussion rather pointless.

Peace and Merry Christmas to everyone

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

Copy link to clipboard

Copied

LATEST

Aha!

It's very easy to self-define the cases!

"It works in this case, this one … and this other one! …

If it doesn't work in that case, it's not a problem … because I don't care of it!!"

"Italicize all text between parenthesis except acronyms" was the question I've read.

Your interpretation is not mine!

Sorry to have contradicted you, but I don't think like you and I don't use Grep in your way!!

(^/) 

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