0

I like to use GREP in In-Design, the problem is I have a menu like so:

HAMBURGER Johnny's Favorite 3.50

I like Johnny's Favorite to be styled differently. The first part, the dish, may contain separate words like: SPICEY CHICKEN. However the dish is always written in capitals.

So I thought:[^a-z]+ [A-Z][^A-Z]+ Favorite.

Only now the dish is styled too. I am only interested in the favorite part, but it must begin with dish to validate. So I thought maybe I had to group it like so: [^a-z]+ ([A-Z][^A-Z]+ Favorite). But that didn't make any difference.

Any ideas?

4
  • You have [^a-z]+ as part of your search query, so that will be a part of what it finds and applies any changes to, regardless of whether you group it or not. You could use a lookbehind, but a lookbehind must have a calculable length, so you can’t use + in it. You could do something like (?<=\u{3}\s)\u\l+ Favorite, if you’re certain there will always be at least three uppercase letters at the end. Or you could add something unique after the dish name and use nested styles instead. May 17, 2021 at 15:26
  • One of the best ways to match stuff is mathcing for what i dont want in a lookbehind or lookahead
    – joojaa
    May 17, 2021 at 16:39
  • I am trying it right now. I will let you know.
    – Mark
    May 17, 2021 at 18:35
  • Why don't use use TAB separators between the parts of your text lines, because in the end you will likely want to vertically align individual parts for better readability. Right? RegEx will become much simpler afterwards too. Jun 2, 2021 at 9:11

2 Answers 2

3

This should work in your case:

(?<=\u )\u[^\u\s].*Favorite

or the more general:

(?<=\u )\u[^\u\s].*\l

Explanation

(?<=\u ) - first we search for any uppercase character followed by a space (the end of an uppercase word), wrapped in a positive lookbehind so we don't include the match

\u - followed by any uppercase character

[^\u\s] - followed by any non-uppercase and non-whitespace character (this makes sure to include any apostrophes right after the first letter like in D'Angelo's)

.* - followed by zero or more characters of any kind

Favorite - followed by the word Favorite (assuming the text you want to select always ends with that word)

or:

\l followed by a lowercase character (assuming the text you want to select always ends with a lowercase letter and never with an apostrophe or other punctuation)

Usage

Works both with GREP Styles:

and with Find/Change:

7
  • This is better than MG_’s answer, but it still misses the requisite of also checking that an all-caps dish name precedes the string to match, so it will match “HAMBURGER Johnny’s Favorite”, but also just “Johnny’s Favorite”. May 19, 2021 at 19:47
  • @JanusBahsJacquet, I don't understand. Are you referring to the "it must begin with dish to validate" part? I'm not sure I understand that sentence 100%. Do you really think that there are lines with no dish names in all caps which mustn't be matched?
    – Wolff
    May 19, 2021 at 19:52
  • Yeah, that’s the one. It’s not super-clearly worded, but I figure there are probably be lines that don’t have any dish name at all, so the special formatting isn’t wanted there, because that’s specifically for the post-dish-name description bit. May 19, 2021 at 19:55
  • @JanusBahsJacquet, is it better now?
    – Wolff
    May 19, 2021 at 20:13
  • Yeah, that’s about as good as I’ve been able to get it too – perhaps (?<=\u{2} ), just to avoid lines that start with “A Something…”, but otherwise I think that’s as good as it’s going to get. May 19, 2021 at 20:15
0

Given your very specific requirements, this pattern will work:

\b[A-Z][^A-Z]+ \b

Example: regexr.com/5t8lj

enter image description here

3
  • This seems to work if you use it in a GREP Style, but not if you perform a Find/Change. Besides that it includes the "trailing" spaces, so if the applied styling has something like underline or Paragraph Shading, it won't work.
    – Wolff
    May 19, 2021 at 17:56
  • Also this misses the caveat “but it must begin with dish to validate” – this will also match a similar string that isn’t preceded by an all-caps dish name. May 19, 2021 at 19:44
  • Yep, I missed part of the brief. Wolff's got it.
    – MG_
    May 20, 2021 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.